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

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

Closed
languagelawyer opened this issue Jun 27, 2019 · 1 comment
Labels
bug Something isn't working

Comments

@languagelawyer
Copy link

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'
...
@andreasfertig andreasfertig added the bug Something isn't working label Jun 27, 2019
@andreasfertig
Copy link
Owner

Hello @languagelawyer,

thank you (again) for the good analysis. A fix is already in the air.

Andreas

andreasfertig added a commit that referenced this issue Jun 27, 2019
Fixed #199: An additional `,` was added after a template parameter.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants