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 .
The problem appears to be related to this call to ASTContext::setTraversalScope() . 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 . 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!
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 decl.
PS in the meantime you could workaround in your code by visiting VarTemplateSpecializationDecl, and calling getSpecializedTemplateOrPartial().
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.
I am working on a protoype implementation of semantic highlighting . To perform semantic highlighting, I need to visit all the tokens we may want to apply a highlighting to, including template parameters. Due to this bug, for a top-level variable template, the template parameter list never gets visited.