Author: martong Date: Wed May 30 02:19:26 2018 New Revision: 333522 URL: http://llvm.org/viewvc/llvm-project?rev=333522&view=rev Log: [ASTImporter] Corrected lookup at import of templated record decl
Summary: When a CXXRecordDecl under ClassTemplateDecl is imported, check the templated record decl for similarity instead of the template. Reviewers: a.sidorin Reviewed By: a.sidorin Subscribers: martong, cfe-commits Differential Revision: https://reviews.llvm.org/D47313 Patch by Balazs Keri! Modified: cfe/trunk/lib/AST/ASTImporter.cpp cfe/trunk/unittests/AST/ASTImporterTest.cpp Modified: cfe/trunk/lib/AST/ASTImporter.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=333522&r1=333521&r2=333522&view=diff ============================================================================== --- cfe/trunk/lib/AST/ASTImporter.cpp (original) +++ cfe/trunk/lib/AST/ASTImporter.cpp Wed May 30 02:19:26 2018 @@ -2015,7 +2015,14 @@ Decl *ASTNodeImporter::VisitRecordDecl(R if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>()) Found = Tag->getDecl(); } - + + if (D->getDescribedTemplate()) { + if (auto *Template = dyn_cast<ClassTemplateDecl>(Found)) + Found = Template->getTemplatedDecl(); + else + continue; + } + if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) { if (!SearchName) { // If both unnamed structs/unions are in a record context, make sure Modified: cfe/trunk/unittests/AST/ASTImporterTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/ASTImporterTest.cpp?rev=333522&r1=333521&r2=333522&view=diff ============================================================================== --- cfe/trunk/unittests/AST/ASTImporterTest.cpp (original) +++ cfe/trunk/unittests/AST/ASTImporterTest.cpp Wed May 30 02:19:26 2018 @@ -1107,6 +1107,50 @@ TEST(ImportExpr, DependentSizedArrayType has(fieldDecl(hasType(dependentSizedArrayType()))))))); } +TEST_P(ASTImporterTestBase, ImportOfTemplatedDeclOfClassTemplateDecl) { + Decl *FromTU = getTuDecl("template<class X> struct S{};", Lang_CXX); + auto From = + FirstDeclMatcher<ClassTemplateDecl>().match(FromTU, classTemplateDecl()); + ASSERT_TRUE(From); + auto To = cast<ClassTemplateDecl>(Import(From, Lang_CXX)); + ASSERT_TRUE(To); + Decl *ToTemplated = To->getTemplatedDecl(); + Decl *ToTemplated1 = Import(From->getTemplatedDecl(), Lang_CXX); + EXPECT_TRUE(ToTemplated1); + EXPECT_EQ(ToTemplated1, ToTemplated); +} + +TEST_P(ASTImporterTestBase, ImportCorrectTemplatedDecl) { + auto Code = + R"( + namespace x { + template<class X> struct S1{}; + template<class X> struct S2{}; + template<class X> struct S3{}; + } + )"; + Decl *FromTU = getTuDecl(Code, Lang_CXX); + auto FromNs = + FirstDeclMatcher<NamespaceDecl>().match(FromTU, namespaceDecl()); + auto ToNs = cast<NamespaceDecl>(Import(FromNs, Lang_CXX)); + ASSERT_TRUE(ToNs); + auto From = + FirstDeclMatcher<ClassTemplateDecl>().match(FromTU, + classTemplateDecl( + hasName("S2"))); + auto To = + FirstDeclMatcher<ClassTemplateDecl>().match(ToNs, + classTemplateDecl( + hasName("S2"))); + ASSERT_TRUE(From); + ASSERT_TRUE(To); + auto ToTemplated = To->getTemplatedDecl(); + auto ToTemplated1 = + cast<CXXRecordDecl>(Import(From->getTemplatedDecl(), Lang_CXX)); + EXPECT_TRUE(ToTemplated1); + ASSERT_EQ(ToTemplated1, ToTemplated); +} + TEST_P(ASTImporterTestBase, DISABLED_ImportFunctionWithBackReferringParameter) { Decl *From, *To; std::tie(From, To) = getImportedDecl( _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits