[PATCH] D89098: [clang] Fix returning the underlying VarDecl as top-level decl for VarTemplateDecl.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 12 06:32:00 PDT 2020
hokein added a subscriber: rsmith.
hokein added a comment.
> Is this https://github.com/clangd/clangd/issues/554 ? :-)
Yeah, the github issue exposes multiple bugs, this is part of the fix.
The AST of `VarTemplateSpeicalizationDecl` is a bit unusual, given the follow code,
template <typename> bool X = true;
bool Z = X<int>;
TranslationUnitDecl 0x8a2ec28 <<invalid sloc>> <invalid sloc>
|-VarTemplateDecl 0x8a6faf8 </tmp/t.cpp:1:1, col:30> col:26 X
| |-TemplateTypeParmDecl 0x8a6f9c0 <col:11> col:19 typename depth 0 index 0
| |-VarDecl 0x8a6fa90 <col:21, col:30> col:26 X 'bool' cinit
| | `-CXXBoolLiteralExpr 0x8a6fb98 <col:30> 'bool' true
| `-VarTemplateSpecializationDecl 0x8a6fd08 <col:21, col:30> col:26 used X 'bool' cinit
| |-TemplateArgument type 'int'
| | `-BuiltinType 0x8a2ed20 'int'
| `-CXXBoolLiteralExpr 0x8a6fb98 <col:30> 'bool' true
|-VarDecl 0x8a6fbb8 <line:2:1, col:15> col:6 Z 'bool' cinit
| `-ImplicitCastExpr 0x8a6ff28 <col:10, col:15> 'bool' <LValueToRValue>
| `-DeclRefExpr 0x8a6fed8 <col:10, col:15> 'bool' lvalue VarTemplateSpecialization 0x8a6fd08 'X' 'bool'
`-VarTemplateSpecializationDecl 0x8a6fd08 <line:1:21, col:30> col:26 used X 'bool' cinit <---- here
|-TemplateArgument type 'int'
| `-BuiltinType 0x8a2ed20 'int'
`-CXXBoolLiteralExpr 0x8a6fb98 <col:30> 'bool' true
Note that the implicitly-instantiated `VarTemplateSpecializationDecl` is one of `TranslationUnitDecl::decls()`, this is different than function/class templates -- for function/class templates, only *explicit* template specializations will be in the `TranslationUnitDecl::decls()`
Related code is at https://github.com/llvm/llvm-project/blob/master/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp#L5015. @rsmith do you think this is expected? or we should fix that? like making it align with function/class templates?
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D89098/new/
https://reviews.llvm.org/D89098
More information about the cfe-commits
mailing list