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

Incorrect depth for SubstTemplateTypeParmType for alias template substitution. #55886

Open
mizvekov opened this issue Jun 5, 2022 · 2 comments
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema"

Comments

@mizvekov
Copy link
Contributor

mizvekov commented Jun 5, 2022

Our substitution of alias templates is leaving behind a SubstTemplateTypeParmType pointing to TemplateTypeParmType with incorrect depth.

Example: (https://godbolt.org/z/r3GPj7GGn)

template<class T> struct C {
  template<class U> using type1 = U (T);
};
using type2 = typename C<int>::type1<void>;

AST dump of type2:

`-TypeAliasDecl 0x56240cfed3e8 <line:4:1, col:42> col:7 type2 'typename C<int>::type1<void>':'void (int)'
  `-ElaboratedType 0x56240cfed340 'typename C<int>::type1<void>' sugar
    `-TemplateSpecializationType 0x56240cfce350 'type1<void>' sugar alias type1
      |-TemplateArgument type 'void'
      | `-BuiltinType 0x56240cf831b0 'void'
      `-FunctionProtoType 0x56240cfce2f0 'void (int)' cdecl
        |-SubstTemplateTypeParmType 0x56240cfce290 'void' sugar
        | |-TemplateTypeParmType 0x56240cfcdfa0 'U' dependent depth 0 index 0
        | | `-TemplateTypeParm 0x56240cfcdf50 'U'
        | `-BuiltinType 0x56240cf831b0 'void'
        `-SubstTemplateTypeParmType 0x56240cfcdfe0 'int' sugar
          |-TemplateTypeParmType 0x56240cfcd590 'T' dependent depth 0 index 0
          | `-TemplateTypeParm 0x56240cfcd510 'T'
          `-BuiltinType 0x56240cf83250 'int'

Ie notice in the AST both T and U are at the same depth, 0.

This happens because we substitute T early into the alias, which pulls U down one level, and then we substitute U.
This flattens everything down to ground level.

@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" and removed new issue labels Jun 5, 2022
@llvmbot
Copy link
Collaborator

llvmbot commented Jun 5, 2022

@llvm/issue-subscribers-clang-frontend

@mizvekov
Copy link
Contributor Author

MR for fix: https://reviews.llvm.org/D127351

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"
Projects
None yet
Development

No branches or pull requests

3 participants