Skip to content

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

Open
@wangbo15

Description

@wangbo15

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"diverges-from:edgDoes the clang frontend diverge from edg compilerdiverges-from:gccDoes the clang frontend diverge from gcc on this issuediverges-from:msvcDoes the clang frontend diverge from msvc on this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions