[PATCH] D99421: [ASTImporter] Import member specialization/instantiation of enum decls
Gabor Marton via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 26 09:29:49 PDT 2021
martong created this revision.
martong added reviewers: teemperor, shafik, balazske, steakhal.
Herald added subscribers: whisperity, gamesh411, Szelethus, dkrupp, rnkovacs.
Herald added a reviewer: a.sidorin.
martong requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
We do the import of the member enum specialization similarly to as we do
with member CXXRecordDecl specialization.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D99421
Files:
clang/lib/AST/ASTImporter.cpp
clang/unittests/AST/ASTImporterTest.cpp
Index: clang/unittests/AST/ASTImporterTest.cpp
===================================================================
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -6236,6 +6236,26 @@
EXPECT_NE(FromFD->getCapturedVLAType(), ToFD->getCapturedVLAType());
}
+TEST_P(ASTImporterOptionSpecificTestBase, Maci) {
+ Decl *FromTU = getTuDecl(
+ R"(
+ template <class T> struct A {
+ enum tagname { enumerator };
+ };
+ template struct A<int>;
+ )",
+ Lang_CXX03);
+ auto *FromD = FirstDeclMatcher<EnumDecl>().match(
+ FromTU, enumDecl(hasName("tagname"),
+ hasParent(classTemplateSpecializationDecl())));
+ ASSERT_TRUE(FromD);
+ ASSERT_TRUE(FromD->getMemberSpecializationInfo());
+
+ auto *ToD = Import(FromD, Lang_CXX03);
+ EXPECT_TRUE(ToD);
+ EXPECT_TRUE(ToD->getMemberSpecializationInfo());
+}
+
INSTANTIATE_TEST_CASE_P(ParameterizedTests, ASTImporterLookupTableTest,
DefaultTestValuesForRunOptions, );
Index: clang/lib/AST/ASTImporter.cpp
===================================================================
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -2732,7 +2732,20 @@
D2->setBraceRange(ToBraceRange);
D2->setAccess(D->getAccess());
D2->setLexicalDeclContext(LexicalDC);
- LexicalDC->addDeclInternal(D2);
+ addDeclToContexts(D, D2);
+
+ if (MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo()) {
+ TemplateSpecializationKind SK = MemberInfo->getTemplateSpecializationKind();
+ EnumDecl *FromInst = D->getInstantiatedFromMemberEnum();
+ if (Expected<EnumDecl *> ToInstOrErr = import(FromInst))
+ D2->setInstantiationOfMemberEnum(*ToInstOrErr, SK);
+ else
+ return ToInstOrErr.takeError();
+ if (ExpectedSLoc POIOrErr = import(MemberInfo->getPointOfInstantiation()))
+ D2->getMemberSpecializationInfo()->setPointOfInstantiation(*POIOrErr);
+ else
+ return POIOrErr.takeError();
+ }
// Import the definition
if (D->isCompleteDefinition())
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99421.333569.patch
Type: text/x-patch
Size: 2086 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210326/bea7d9da/attachment.bin>
More information about the cfe-commits
mailing list