{"url":"https://api.github.com/repos/llvm/llvm-project/issues/90760","repository_url":"https://api.github.com/repos/llvm/llvm-project","labels_url":"https://api.github.com/repos/llvm/llvm-project/issues/90760/labels{/name}","comments_url":"https://api.github.com/repos/llvm/llvm-project/issues/90760/comments","events_url":"https://api.github.com/repos/llvm/llvm-project/issues/90760/events","html_url":"https://github.com/llvm/llvm-project/pull/90760","id":2274007847,"node_id":"PR_kwDOBITxeM5uRyix","number":90760,"title":"[Clang][Sema] Explicit template arguments are not substituted into the exception specification of a function","user":{"login":"sdkrystian","id":16629302,"node_id":"MDQ6VXNlcjE2NjI5MzAy","avatar_url":"https://avatars.githubusercontent.com/u/16629302?v=4","gravatar_id":"","url":"https://api.github.com/users/sdkrystian","html_url":"https://github.com/sdkrystian","followers_url":"https://api.github.com/users/sdkrystian/followers","following_url":"https://api.github.com/users/sdkrystian/following{/other_user}","gists_url":"https://api.github.com/users/sdkrystian/gists{/gist_id}","starred_url":"https://api.github.com/users/sdkrystian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sdkrystian/subscriptions","organizations_url":"https://api.github.com/users/sdkrystian/orgs","repos_url":"https://api.github.com/users/sdkrystian/repos","events_url":"https://api.github.com/users/sdkrystian/events{/privacy}","received_events_url":"https://api.github.com/users/sdkrystian/received_events","type":"User","user_view_type":"public","site_admin":false},"labels":[{"id":1958965060,"node_id":"MDU6TGFiZWwxOTU4OTY1MDYw","url":"https://api.github.com/repos/llvm/llvm-project/labels/clang","name":"clang","color":"79b5d1","default":false,"description":"Clang issues not falling into any other category"},{"id":1958998266,"node_id":"MDU6TGFiZWwxOTU4OTk4MjY2","url":"https://api.github.com/repos/llvm/llvm-project/labels/clang:frontend","name":"clang:frontend","color":"3b12ce","default":false,"description":"Language frontend issues, e.g. anything involving \"Sema\""}],"state":"closed","locked":false,"assignees":[],"milestone":null,"comments":3,"created_at":"2024-05-01T18:54:13Z","updated_at":"2024-05-08T00:04:58Z","closed_at":"2024-05-08T00:04:58Z","assignee":null,"author_association":"MEMBER","issue_field_values":[],"type":null,"active_lock_reason":null,"draft":false,"pull_request":{"url":"https://api.github.com/repos/llvm/llvm-project/pulls/90760","html_url":"https://github.com/llvm/llvm-project/pull/90760","diff_url":"https://github.com/llvm/llvm-project/pull/90760.diff","patch_url":"https://github.com/llvm/llvm-project/pull/90760.patch","merged_at":"2024-05-08T00:04:57Z"},"body":"[[temp.deduct.general] p6](eel.is/c++draft/temp.deduct.general#6) states:\r\n> At certain points in the template argument deduction process it is necessary to take a function type that makes use of template parameters and replace those template parameters with the corresponding template arguments.\r\nThis is done at the beginning of template argument deduction when any explicitly specified template arguments are substituted into the function type, and again at the end of template argument deduction when any template arguments that were deduced or obtained from default arguments are substituted.\r\n\r\n[[temp.deduct.general] p7](eel.is/c++draft/temp.deduct.general#7) goes on to say:\r\n> The _deduction substitution loci_ are\r\n> - the function type outside of the _noexcept-specifier_,\r\n> - the explicit-specifier,\r\n> - the template parameter declarations, and\r\n> - the template argument list of a partial specialization\r\n>\r\n>  The substitution occurs in all types and expressions that are used in the deduction substitution loci. [...]\r\n\r\nConsider the following:\r\n```cpp\r\nstruct A\r\n{\r\n    static constexpr bool x = true;\r\n};\r\n\r\ntemplate<typename T, typename U>\r\nvoid f(T, U) noexcept(T::x); // #1\r\n\r\ntemplate<typename T, typename U>\r\nvoid f(T, U*) noexcept(T::y); // #2\r\n\r\ntemplate<>\r\nvoid f<A>(A, int*) noexcept; // clang currently accepts, GCC and EDG reject\r\n```\r\n\r\nCurrently, `Sema::SubstituteExplicitTemplateArguments` will substitute into the _noexcept-specifier_ when deducing template arguments from a function declaration or when deducing template arguments for taking the address of a function template (and the substitution is treated as a SFINAE context). In the above example, `#1` is selected as the primary template because substitution of the explicit template arguments into the _noexcept-specifier_ of `#2` failed, which resulted in the candidate being ignored.\r\n\r\nThis behavior is incorrect ([note 4](http://eel.is/c++draft/temp.deduct.general#note-4) says as much), and this patch corrects it by deferring all substitution into the _noexcept-specifier_ until it is instantiated. \r\n\r\nAs part of the necessary changes to make this patch work, the instantiation of the exception specification of a function template specialization when taking the address of a function template is changed to only occur for the function selected by overload resolution per [[except.spec] p13.1](http://eel.is/c++draft/except.spec#13.1) (as opposed to being instantiated for every candidate).","closed_by":{"login":"sdkrystian","id":16629302,"node_id":"MDQ6VXNlcjE2NjI5MzAy","avatar_url":"https://avatars.githubusercontent.com/u/16629302?v=4","gravatar_id":"","url":"https://api.github.com/users/sdkrystian","html_url":"https://github.com/sdkrystian","followers_url":"https://api.github.com/users/sdkrystian/followers","following_url":"https://api.github.com/users/sdkrystian/following{/other_user}","gists_url":"https://api.github.com/users/sdkrystian/gists{/gist_id}","starred_url":"https://api.github.com/users/sdkrystian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sdkrystian/subscriptions","organizations_url":"https://api.github.com/users/sdkrystian/orgs","repos_url":"https://api.github.com/users/sdkrystian/repos","events_url":"https://api.github.com/users/sdkrystian/events{/privacy}","received_events_url":"https://api.github.com/users/sdkrystian/received_events","type":"User","user_view_type":"public","site_admin":false},"reactions":{"url":"https://api.github.com/repos/llvm/llvm-project/issues/90760/reactions","total_count":0,"+1":0,"-1":0,"laugh":0,"hooray":0,"confused":0,"heart":0,"rocket":0,"eyes":0},"timeline_url":"https://api.github.com/repos/llvm/llvm-project/issues/90760/timeline","performed_via_github_app":null,"state_reason":null}