[clangd-dev] Strange issue with RecursiveASTVisitor, TestTU, and variable templates

Ilya Biryukov via clangd-dev clangd-dev at lists.llvm.org
Tue Apr 23 01:00:09 PDT 2019

Hi Nathan,

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.
The latter seems cleaner, I'll try it out and see if anything breaks.

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

PS in the meantime you could workaround in your code by visiting
VarTemplateSpecializationDecl, and calling

On Sun, Apr 21, 2019 at 11:40 PM Nathan Ridge via clangd-dev <
clangd-dev at lists.llvm.org> wrote:

> Hi folks,
> 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.
> I posted a patch with a test case illustrating the problem [1].
> 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.
> 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.
> Any guidance would be appreciated!
> Thanks,
> Nate
> [1] https://reviews.llvm.org/D60954
> [2]
> https://github.com/llvm/llvm-project/blob/bc76bbcaa0553b29f904d45cef9cc2a65d589f50/clang-tools-extra/clangd/ClangdUnit.cpp#L356
> [3]
> https://github.com/llvm/llvm-project/blob/bc76bbcaa0553b29f904d45cef9cc2a65d589f50/clang/lib/Parse/ParseDecl.cpp#L2224
> _______________________________________________
> clangd-dev mailing list
> clangd-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/clangd-dev

Ilya Biryukov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/clangd-dev/attachments/20190423/bd15f499/attachment-0001.html>

More information about the clangd-dev mailing list