Author: martong Date: Wed May 23 07:24:02 2018 New Revision: 333086 URL: http://llvm.org/viewvc/llvm-project?rev=333086&view=rev Log: [ASTImporter] Fix missing implict CXXRecordDecl in ClassTemplateSpecializationDecl
Summary: Currently we do not import the implicit CXXRecordDecl of a ClassTemplateSpecializationDecl. This patch fixes it. Reviewers: a.sidorin, xazax.hun, r.stahl Subscribers: rnkovacs, dkrupp, cfe-commits Differential Revision: https://reviews.llvm.org/D47057 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=333086&r1=333085&r2=333086&view=diff ============================================================================== --- cfe/trunk/lib/AST/ASTImporter.cpp (original) +++ cfe/trunk/lib/AST/ASTImporter.cpp Wed May 23 07:24:02 2018 @@ -1959,14 +1959,20 @@ Decl *ASTNodeImporter::VisitRecordDecl(R // but this particular declaration is not that definition, import the // definition and map to that. TagDecl *Definition = D->getDefinition(); - if (Definition && Definition != D) { + if (Definition && Definition != D && + // In contrast to a normal CXXRecordDecl, the implicit + // CXXRecordDecl of ClassTemplateSpecializationDecl is its redeclaration. + // The definition of the implicit CXXRecordDecl in this case is the + // ClassTemplateSpecializationDecl itself. Thus, we start with an extra + // condition in order to be able to import the implict Decl. + !D->isImplicit()) { Decl *ImportedDef = Importer.Import(Definition); if (!ImportedDef) return nullptr; return Importer.Imported(D, ImportedDef); } - + // Import the major distinguishing characteristics of this record. DeclContext *DC, *LexicalDC; DeclarationName Name; Modified: cfe/trunk/unittests/AST/ASTImporterTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/ASTImporterTest.cpp?rev=333086&r1=333085&r2=333086&view=diff ============================================================================== --- cfe/trunk/unittests/AST/ASTImporterTest.cpp (original) +++ cfe/trunk/unittests/AST/ASTImporterTest.cpp Wed May 23 07:24:02 2018 @@ -1363,6 +1363,22 @@ TEST_P(ASTImporterTestBase, ShouldImport Decl *From, *To; std::tie(From, To) = getImportedDecl( R"( + struct declToImport { + }; + )", + Lang_CXX, "", Lang_CXX); + + MatchVerifier<Decl> Verifier; + // Match the implicit Decl. + auto Matcher = cxxRecordDecl(has(cxxRecordDecl())); + ASSERT_TRUE(Verifier.match(From, Matcher)); + EXPECT_TRUE(Verifier.match(To, Matcher)); +} + +TEST_P(ASTImporterTestBase, ShouldImportImplicitCXXRecordDeclOfClassTemplate) { + Decl *From, *To; + std::tie(From, To) = getImportedDecl( + R"( template <typename U> struct declToImport { }; @@ -1378,7 +1394,7 @@ TEST_P(ASTImporterTestBase, ShouldImport TEST_P( ASTImporterTestBase, - DISABLED_ShouldImportImplicitCXXRecordDeclOfClassTemplateSpecializationDecl) { + ShouldImportImplicitCXXRecordDeclOfClassTemplateSpecializationDecl) { Decl *From, *To; std::tie(From, To) = getImportedDecl( R"( _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits