Open Quuxplusone opened 9 years ago
Bugzilla Link | PR20666 |
Status | NEW |
Importance | P normal |
Reported by | Eli Bendersky (eliben@gmail.com) |
Reported on | 2014-08-14 18:24:01 -0700 |
Last modified on | 2019-01-14 02:54:22 -0800 |
Version | trunk |
Hardware | PC Linux |
CC | dgregor@apple.com, eliben@gmail.com, jbytheway+llvm@gmail.com, llvm-bugs@lists.llvm.org, nlewycky@google.com, richard-llvm@metafoo.co.uk, steveire@gmail.com |
Fixed by commit(s) | |
Attachments | |
Blocks | |
Blocked by | |
See also |
Isn't FD->getTemplateSpecializationKind() == TSK_ExplicitSpecializationDeclaration?
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.
More symptoms of this:
template<typename T> void f() {}
extern template void f<int>();
extern template void f<int>();
... has no declarations on either line 2 or line 3, and only one declaration of
'void f<int>()' in the AST. And:
template<typename T> void f() {}
typedef int Foo;
extern template void f<Foo>();
... has no references to Foo in the AST (defeating rename refactorings and the
like).
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<class>
void template_function() {}
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].