Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Clang] template class with default non-type parameter is never matched in return type of function with variadic template parameter #121381

Open
wangbo15 opened this issue Dec 31, 2024 · 1 comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" diverges-from:edg Does the clang frontend diverge from edg compiler diverges-from:gcc Does the clang frontend diverge from gcc on this issue diverges-from:msvc Does the clang frontend diverge from msvc on this issue

Comments

@wangbo15
Copy link

The following valid program is rejected by Clang:

template<typename T1, int T2 = 0>
struct tuple {};

template<typename... Args>
tuple<Args...> foo(){
    return tuple<Args...>{}; 
}

int main()
{
  foo<int>();
}

The code can normally compile if the default template parameter of tuple does not exist.

GCC, MSVC, and EDG all accept it.

clang rejects it with:

<source>:11:3: error: no matching function for call to 'foo'
   11 |   foo<int>();
      |   ^~~~~~~~
<source>:5:16: note: candidate template ignored: substitution failure [with Args = <int>]: template argument for non-type template parameter must be an expression
    5 | tuple<Args...> foo(){
      | ~~~~~          ^
1 error generated.

Please see https://godbolt.org/z/6h8vWx47x

@github-actions github-actions bot added the clang Clang issues not falling into any other category label Dec 31, 2024
@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" diverges-from:gcc Does the clang frontend diverge from gcc on this issue diverges-from:msvc Does the clang frontend diverge from msvc on this issue diverges-from:edg Does the clang frontend diverge from edg compiler and removed clang Clang issues not falling into any other category labels Dec 31, 2024
@llvmbot
Copy link
Member

llvmbot commented Dec 31, 2024

@llvm/issue-subscribers-clang-frontend

Author: Bo Wang (wangbo15)

The following valid program is rejected by Clang:
template&lt;typename T1, int T2 = 0&gt;
struct tuple {};

template&lt;typename... Args&gt;
tuple&lt;Args...&gt; foo(){
    return tuple&lt;Args...&gt;{}; 
}

int main()
{
  foo&lt;int&gt;();
}

The code can normally compile if the default template parameter of tuple does not exist.

GCC, MSVC, and EDG all accept it.

clang rejects it with:

&lt;source&gt;:11:3: error: no matching function for call to 'foo'
   11 |   foo&lt;int&gt;();
      |   ^~~~~~~~
&lt;source&gt;:5:16: note: candidate template ignored: substitution failure [with Args = &lt;int&gt;]: template argument for non-type template parameter must be an expression
    5 | tuple&lt;Args...&gt; foo(){
      | ~~~~~          ^
1 error generated.

Please see https://godbolt.org/z/6h8vWx47x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" diverges-from:edg Does the clang frontend diverge from edg compiler diverges-from:gcc Does the clang frontend diverge from gcc on this issue diverges-from:msvc Does the clang frontend diverge from msvc on this issue
Projects
None yet
Development

No branches or pull requests

3 participants