Skip to content

Commit 4de971c

Browse files
authored
[clang][ASTImporter] import InstantiatedFromMember of ClassTemplateSpecializationDecl (#76493)
import of `ClassTemplateSpecializationDecl` didn't set `InstantiatedFromMember` and this makes ast-dump crash. import and set `InstantiatedFromMember`. fix [issue](#76469) Co-authored-by: huqizhi <[email protected]>
1 parent 26ff659 commit 4de971c

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

clang/lib/AST/ASTImporter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6141,6 +6141,11 @@ ExpectedDecl ASTNodeImporter::VisitClassTemplateSpecializationDecl(
61416141
InsertPos))
61426142
// Add this partial specialization to the class template.
61436143
ClassTemplate->AddPartialSpecialization(PartSpec2, InsertPos);
6144+
if (Expected<ClassTemplatePartialSpecializationDecl *> ToInstOrErr =
6145+
import(PartialSpec->getInstantiatedFromMember()))
6146+
PartSpec2->setInstantiatedFromMember(*ToInstOrErr);
6147+
else
6148+
return ToInstOrErr.takeError();
61446149

61456150
updateLookupTableForTemplateParameters(*ToTPList);
61466151
} else { // Not a partial specialization.

clang/unittests/AST/ASTImporterTest.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9342,6 +9342,39 @@ TEST_P(ASTImporterOptionSpecificTestBase, ImportConflictTypeAliasTemplate) {
93429342
EXPECT_FALSE(ImportedCallable);
93439343
}
93449344

9345+
AST_MATCHER(ClassTemplateSpecializationDecl, hasInstantiatedFromMember) {
9346+
if (auto Instantiate = Node.getInstantiatedFrom()) {
9347+
if (auto *FromPartialSpecialization =
9348+
Instantiate.get<ClassTemplatePartialSpecializationDecl *>()) {
9349+
return nullptr != FromPartialSpecialization->getInstantiatedFromMember();
9350+
}
9351+
}
9352+
return false;
9353+
}
9354+
9355+
TEST_P(ASTImporterOptionSpecificTestBase, ImportInstantiatedFromMember) {
9356+
const char *Code =
9357+
R"(
9358+
template <typename> struct B {
9359+
template <typename, bool = false> union D;
9360+
template <typename T> union D<T> {};
9361+
D<int> d;
9362+
};
9363+
B<int> b;
9364+
)";
9365+
Decl *FromTU = getTuDecl(Code, Lang_CXX11);
9366+
auto *FromD = FirstDeclMatcher<ClassTemplateSpecializationDecl>().match(
9367+
FromTU, classTemplateSpecializationDecl(hasName("D"),
9368+
hasInstantiatedFromMember()));
9369+
auto *FromPartialSpecialization =
9370+
cast<ClassTemplatePartialSpecializationDecl *>(
9371+
FromD->getInstantiatedFrom());
9372+
ASSERT_TRUE(FromPartialSpecialization->getInstantiatedFromMember());
9373+
auto *ImportedPartialSpecialization =
9374+
Import(FromPartialSpecialization, Lang_CXX11);
9375+
EXPECT_TRUE(ImportedPartialSpecialization->getInstantiatedFromMember());
9376+
}
9377+
93459378
INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest,
93469379
DefaultTestValuesForRunOptions);
93479380

0 commit comments

Comments
 (0)