Skip to content

Generated function specializations: Parameters generated from parameter packs use the same name #62

@neobrain

Description

@neobrain

C++ Insights generates explicit specializations for template functions. When the primary function template contains any parameter packs, the parameters generated from the pack in the specialization will all use the same name. It would be nice for the names to be distinguished.

See below:

Input C++ Insights Desired
template<typename... T>
int func(T... t) {
    return func(t...);
}
int _ = func(5, 5);

#ifdef USE_TEMPLATE
template<>
int func<int, int>(int t, int t)
{
  return func(t, t);
}
#endif
int _ = func(5, 5);

#ifdef USE_TEMPLATE
template<>
int func<int, int>(int t1, int t2)
{
  return func(t1, t2);
}
#endif
int _ = func(5, 5);

Fixing this requires C++ Insights to detect which ParmVarDecls in a specialized FunctionDecl correspond to parameter packs in the primary function template (and then just suffix them with a counter, for instance). Annoyingly, I haven't found a good way in libclang to do so other than traversing all primary function template parameters and comparing them by name to the current ParmVarDecl :/

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions