<div dir="ltr"><div dir="ltr"><div dir="ltr">Hi Nathan,<div><br></div><div>I agree that looks weird, behavior for all templates should be consistent. We can either workaround this in our code or update the clang frontend to pass the template rather than the specialization to HandleTopLevelDecl.</div><div>The latter seems cleaner, I'll try it out and see if anything breaks.</div><div><br></div><div>Could you describe the problem you are trying to solve? Maybe there are alternative ways to go about it that don't involve looking at the template decl.</div><div><br></div><div>PS in the meantime you could workaround in your code by visiting VarTemplateSpecializationDecl, and calling getSpecializedTemplateOrPartial().<br></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Apr 21, 2019 at 11:40 PM Nathan Ridge via clangd-dev <<a href="mailto:clangd-dev@lists.llvm.org">clangd-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi folks,<br>
<br>
I've run into a strange issue when trying to use a RecursiveASTVisitor on an AST created by TestTU::build(): it seems that top-level variable template declarations are never visited, only their inner VarDecl is.<br>
<br>
I posted a patch with a test case illustrating the problem [1].<br>
<br>
The problem appears to be related to this call to ASTContext::setTraversalScope() [2]. If I change that to set the traversal scope to the entire translation unit, the variable template declaration is visited correctly.<br>
<br>
I did some further digging and found that the proximate cause of the problem is this line in clang's parser code [3]. However, I'm out of my depth here and don't know if this is actually a parser / AST bug, or a bug in how TestTU / ParsedAST are using these APIs.<br>
<br>
Any guidance would be appreciated!<br>
<br>
Thanks,<br>
Nate<br>
<br>
[1] <a href="https://reviews.llvm.org/D60954" rel="noreferrer" target="_blank">https://reviews.llvm.org/D60954</a><br>
[2] <a href="https://github.com/llvm/llvm-project/blob/bc76bbcaa0553b29f904d45cef9cc2a65d589f50/clang-tools-extra/clangd/ClangdUnit.cpp#L356" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/blob/bc76bbcaa0553b29f904d45cef9cc2a65d589f50/clang-tools-extra/clangd/ClangdUnit.cpp#L356</a><br>
[3] <a href="https://github.com/llvm/llvm-project/blob/bc76bbcaa0553b29f904d45cef9cc2a65d589f50/clang/lib/Parse/ParseDecl.cpp#L2224" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/blob/bc76bbcaa0553b29f904d45cef9cc2a65d589f50/clang/lib/Parse/ParseDecl.cpp#L2224</a><br>
_______________________________________________<br>
clangd-dev mailing list<br>
<a href="mailto:clangd-dev@lists.llvm.org" target="_blank">clangd-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/clangd-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/clangd-dev</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>Regards,</div><div>Ilya Biryukov</div></div></div></div></div>