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

Nathan Ridge via clangd-dev clangd-dev at lists.llvm.org
Sun Apr 21 14:40:10 PDT 2019


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


More information about the clangd-dev mailing list