martong updated this revision to Diff 146845.
martong marked 4 inline comments as done.
martong added a comment.
- Add test for removeDecl, remove unrelated tests
Repository:
rC Clang
https://reviews.llvm.org/D46835
Files:
lib/AST/DeclBase.cpp
unittests/AST/ASTImporterTest.cpp
unittests/AST/MatchVerifier.h
Index: unittests/AST/MatchVerifier.h
===================================================================
--- unittests/AST/MatchVerifier.h
+++ unittests/AST/MatchVerifier.h
@@ -28,11 +28,12 @@
namespace clang {
namespace ast_matchers {
-enum Language {
+enum Language {
Lang_C,
Lang_C89,
Lang_CXX,
Lang_CXX11,
+ Lang_CXX14,
Lang_OpenCL,
Lang_OBJCXX
};
@@ -113,6 +114,10 @@
Args.push_back("-std=c++11");
FileName = "input.cc";
break;
+ case Lang_CXX14:
+ Args.push_back("-std=c++14");
+ FileName = "input.cc";
+ break;
case Lang_OpenCL:
FileName = "input.cl";
break;
Index: unittests/AST/ASTImporterTest.cpp
===================================================================
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -52,6 +52,9 @@
case Lang_CXX11:
BasicArgs = {"-std=c++11", "-frtti"};
break;
+ case Lang_CXX14:
+ BasicArgs = {"-std=c++14", "-frtti"};
+ break;
case Lang_OpenCL:
case Lang_OBJCXX:
llvm_unreachable("Not implemented yet!");
@@ -1764,5 +1767,38 @@
compoundStmt(has(callExpr(has(unresolvedMemberExpr())))))))));
}
+struct DeclContextTest : ASTImporterTestBase {};
+
+TEST_P(DeclContextTest, removeDeclOfClassTemplateSpecialization) {
+ Decl *TU = getTuDecl(
+ R"(
+ namespace NS {
+
+ template <typename T>
+ struct S {};
+ template struct S<int>;
+
+ inline namespace INS {
+ template <typename T>
+ struct S {};
+ template struct S<int>;
+ }
+
+ }
+ )", Lang_CXX11, "input0.cc");
+ auto *NS = FirstDeclMatcher<NamespaceDecl>().match(
+ TU, namespaceDecl());
+ auto *Spec = FirstDeclMatcher<ClassTemplateSpecializationDecl>().match(
+ TU, classTemplateSpecializationDecl());
+ ASSERT_TRUE(NS->containsDecl(Spec));
+
+ NS->removeDecl(Spec);
+ EXPECT_FALSE(NS->containsDecl(Spec));
+}
+
+INSTANTIATE_TEST_CASE_P(
+ ParameterizedTests, DeclContextTest,
+ ::testing::Values(ArgVector(), ArgVector{"-fdelayed-template-parsing"}),);
+
} // end namespace ast_matchers
} // end namespace clang
Index: lib/AST/DeclBase.cpp
===================================================================
--- lib/AST/DeclBase.cpp
+++ lib/AST/DeclBase.cpp
@@ -1350,6 +1350,8 @@
(D->NextInContextAndBits.getPointer() || D == LastDecl));
}
+static bool shouldBeHidden(NamedDecl *D);
+
void DeclContext::removeDecl(Decl *D) {
assert(D->getLexicalDeclContext() == this &&
"decl being removed from non-lexical context");
@@ -1372,14 +1374,18 @@
}
}
}
-
+
// Mark that D is no longer in the decl chain.
D->NextInContextAndBits.setPointer(nullptr);
// Remove D from the lookup table if necessary.
if (isa<NamedDecl>(D)) {
auto *ND = cast<NamedDecl>(D);
+ // Do not try to remove the declaration if that is invisible to qualified
+ // lookup. E.g. template specializations are skipped.
+ if (shouldBeHidden(ND)) return;
+
// Remove only decls that have a name
if (!ND->getDeclName()) return;
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits