Open llvmbot opened 10 years ago
I ran into an aspect of this issue while trying to improve include-what-you-use's handling of arguments to explicit template declarations and similar things.
For example, in the following code:
using my_int = int; constexpr int h(int n) { return n*2; }
template
template void template_function<my_int[h(7)]>();
the relevant part of the AST is just:
-FunctionTemplateDecl 0x561a3ac05e20 <line:4:1, line:5:27> col:6 template_function |-TemplateTypeParmDecl 0x561a3ac05c78 <line:4:10> col:10 class depth 0 index 0 |-FunctionDecl 0x561a3ac05d80 <line:5:1, col:27> col:6 template_function 'void ()' |
-CompoundStmt 0x561a3ac05e70 <col:26, col:27>
-FunctionDecl 0x561a3ac06138 <col:1, col:27> col:6 template_function 'void ()' |-TemplateArgument type 'int [14]'
-CompoundStmt 0x561a3ac05e70 <col:26, col:27>
To compute uses correctly we need to see that the argument mentioned my_int, rather than int, and that h was called. I'd expect DeclRefExpr entries somewhere in the AST for both my_int and h, but as far as I can see there is nothing. We just get the type int[14].
More symptoms of this:
template
... has no declarations on either line 2 or line 3, and only one declaration of 'void f
template
... has no references to Foo in the AST (defeating rename refactorings and the like).
Specifically, the problem we encounter is that its source location is incorrect. It's <line:2:3, line:4:3>, same as the template decl.
Isn't FD->getTemplateSpecializationKind() == TSK_ExplicitSpecializationDeclaration?
Extended Description
Explicit (extern) template declarations have no representation in the AST:
template
int __ostream_insert() {
return 0;
}
extern template int __ostream_insert();
template<> int __ostream_insert() {
return 1;
}
Produces:
It appears as a child of the FunctionTemplateDecl:
But the source location is incorrect (points to the parent template, not the extern instantiation.