[PATCH] D90763: Traverse-ignore explicit template instantiations
Aaron Ballman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 5 12:54:24 PST 2020
aaron.ballman added inline comments.
================
Comment at: clang/lib/ASTMatchers/ASTMatchFinder.cpp:503
TraversalKind Traversal, BindKind Bind) {
+ auto ScopedTraversal = TraversingTemplateInstantiationNotSpelledInSource;
+
----------------
Please spell this type out rather than use auto.
================
Comment at: clang/lib/ASTMatchers/ASTMatchFinder.cpp:506
+ if (const auto *CTSD = Node.get<ClassTemplateSpecializationDecl>()) {
+ auto SK = CTSD->getSpecializationKind();
+ if (SK == TSK_ExplicitInstantiationDeclaration ||
----------------
Same here, though this could also be simplified to:
```
ScopedTraversal = (SK == TSK_ExplicitInstantiationDeclaration || SK == TSK_ExplicitInstantiationDefinition);
```
================
Comment at: clang/unittests/AST/ASTTraverserTest.cpp:1092
+
+// Explicit instantiation of template functions do not appear in the AST
+template float timesTwo(float);
----------------
Huh, do you have any idea if that's a bug? We have `ClassTemplateSpecializationDecl` and `VarTemplateSpecializationDecl`, but we have `FunctionTemplateSpecializationInfo` that doesn't generate an AST node and no mention of why in the comments that I've spotted yet.
================
Comment at: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp:2280
+ EXPECT_TRUE(matches(Code, traverse(TK_AsIs, M)));
+ EXPECT_TRUE(matches(Code, traverse(TK_IgnoreUnlessSpelledInSource, M)));
+ }
----------------
Explicitly instantiating a function template in ignore mode returns false, but explicitly instantiating a class template returns true? Is this intentional or just fallout from the lack of explicit instantiation information in the AST for functions?
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D90763/new/
https://reviews.llvm.org/D90763
More information about the cfe-commits
mailing list