[clang] 4eb8804 - Fix dumping of explicit template specializations
Stephen Kelly via cfe-commits
cfe-commits at lists.llvm.org
Sat Nov 7 14:35:23 PST 2020
Author: Stephen Kelly
Date: 2020-11-07T22:34:16Z
New Revision: 4eb880439a7ec4a0310b630ff89125e00cf200a3
URL: https://github.com/llvm/llvm-project/commit/4eb880439a7ec4a0310b630ff89125e00cf200a3
DIFF: https://github.com/llvm/llvm-project/commit/4eb880439a7ec4a0310b630ff89125e00cf200a3.diff
LOG: Fix dumping of explicit template specializations
This was missing from commit 7efe07a1 (Traverse-ignore explicit template
instantiations, 2020-11-06).
Added:
Modified:
clang/include/clang/AST/ASTNodeTraverser.h
clang/unittests/AST/ASTTraverserTest.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/AST/ASTNodeTraverser.h b/clang/include/clang/AST/ASTNodeTraverser.h
index c3c06bf37f3d..78b2ec5a3dc7 100644
--- a/clang/include/clang/AST/ASTNodeTraverser.h
+++ b/clang/include/clang/AST/ASTNodeTraverser.h
@@ -101,8 +101,14 @@ class ASTNodeTraverser
// Decls within functions are visited by the body.
if (!isa<FunctionDecl>(*D) && !isa<ObjCMethodDecl>(*D)) {
- if (isa<ClassTemplateSpecializationDecl>(*D) && Traversal != TK_AsIs)
- return;
+ if (Traversal != TK_AsIs) {
+ if (const auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
+ auto SK = CTSD->getSpecializationKind();
+ if (SK == TSK_ExplicitInstantiationDeclaration ||
+ SK == TSK_ExplicitInstantiationDefinition)
+ return;
+ }
+ }
if (const auto *DC = dyn_cast<DeclContext>(D))
dumpDeclContext(DC);
}
diff --git a/clang/unittests/AST/ASTTraverserTest.cpp b/clang/unittests/AST/ASTTraverserTest.cpp
index 727a1ffa8395..5e167e4d30b7 100644
--- a/clang/unittests/AST/ASTTraverserTest.cpp
+++ b/clang/unittests/AST/ASTTraverserTest.cpp
@@ -1183,6 +1183,48 @@ ClassTemplateDecl 'TemplStruct'
| `-CompoundStmt
|-AccessSpecDecl
`-FieldDecl 'm_t'
+)cpp");
+ }
+ {
+ auto BN = ast_matchers::match(
+ classTemplateSpecializationDecl(
+ hasTemplateArgument(
+ 0, templateArgument(refersToType(asString("_Bool")))))
+ .bind("templSpec"),
+ AST->getASTContext());
+ EXPECT_EQ(BN.size(), 1u);
+
+ EXPECT_EQ(dumpASTString(TK_AsIs, BN[0].getNodeAs<Decl>("templSpec")),
+ R"cpp(
+ClassTemplateSpecializationDecl 'TemplStruct'
+|-TemplateArgument type _Bool
+| `-BuiltinType
+|-CXXRecordDecl 'TemplStruct'
+|-CXXConstructorDecl 'TemplStruct'
+| `-CompoundStmt
+|-CXXDestructorDecl '~TemplStruct'
+| `-CompoundStmt
+|-CXXMethodDecl 'foo'
+| `-CompoundStmt
+|-AccessSpecDecl
+`-FieldDecl 'm_t'
+)cpp");
+
+ EXPECT_EQ(dumpASTString(TK_IgnoreUnlessSpelledInSource,
+ BN[0].getNodeAs<Decl>("templSpec")),
+ R"cpp(
+ClassTemplateSpecializationDecl 'TemplStruct'
+|-TemplateArgument type _Bool
+| `-BuiltinType
+|-CXXRecordDecl 'TemplStruct'
+|-CXXConstructorDecl 'TemplStruct'
+| `-CompoundStmt
+|-CXXDestructorDecl '~TemplStruct'
+| `-CompoundStmt
+|-CXXMethodDecl 'foo'
+| `-CompoundStmt
+|-AccessSpecDecl
+`-FieldDecl 'm_t'
)cpp");
}
{
More information about the cfe-commits
mailing list