Skip to content

Trailing comma in template-parameter-list when TemplateArgument pack is empty #199

@languagelawyer

Description

@languagelawyer

For the following code

template<typename U, typename ...T>
void f(U, T... rest)
{
  if constexpr (sizeof...(rest) != 0)
    f(rest...);
}

int main()
{
    f(0, 1);
}

cppinsights produce

template<typename U, typename ...T>
void f(U, T... rest)
{
  if constexpr (sizeof...(rest) != 0)
    f(rest...);
}

/* First instantiated from: insights.cpp:10 */
#ifdef INSIGHTS_USE_TEMPLATE
template<>
void f<int, int>(int, int __rest1)
{
  if constexpr(1 != 0) f(__rest1);
  
  
}
#endif


/* First instantiated from: insights.cpp:5 */
#ifdef INSIGHTS_USE_TEMPLATE
template<>
void f<int, >(int)
{
  if constexpr(0 != 0) ;
  
  
}
#endif


int main()
{
  f(0, 1);
}

Note the trailing comma in the second instantiation:

template<>
void f<int, >(int)
          ^ here

Relevant parts of the AST for the first and second instantiations:

| |-FunctionDecl <line:2:1, line:6:1> line:2:6 used f 'void (int, int)'
| | |-TemplateArgument type 'int'
| | |-TemplateArgument pack
| | | `-TemplateArgument type 'int'
| | |-ParmVarDecl <col:8> col:9 'int':'int'
...
| `-FunctionDecl <line:2:1, line:6:1> line:2:6 used f 'void (int)'
|   |-TemplateArgument type 'int'
|   |-TemplateArgument pack
|   |-ParmVarDecl <col:8> col:9 'int':'int'
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions