From: Gabor Marton Date: Wed, 23 May 2018 14:24:02 +0000 (+0000) Subject: [ASTImporter] Fix missing implict CXXRecordDecl in ClassTemplateSpecializationDecl X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=71643f043c06c75323a692818a440bd3fb3635e6;p=clang [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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@333086 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/ASTImporter.cpp b/lib/AST/ASTImporter.cpp index 3c69897436..7e402722b1 100644 --- a/lib/AST/ASTImporter.cpp +++ b/lib/AST/ASTImporter.cpp @@ -1959,14 +1959,20 @@ Decl *ASTNodeImporter::VisitRecordDecl(RecordDecl *D) { // 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; diff --git a/unittests/AST/ASTImporterTest.cpp b/unittests/AST/ASTImporterTest.cpp index 18c8f4cc02..d5827a6a52 100644 --- a/unittests/AST/ASTImporterTest.cpp +++ b/unittests/AST/ASTImporterTest.cpp @@ -1360,6 +1360,22 @@ TEST_P(ASTImporterTestBase, } TEST_P(ASTImporterTestBase, ShouldImportImplicitCXXRecordDecl) { + Decl *From, *To; + std::tie(From, To) = getImportedDecl( + R"( + struct declToImport { + }; + )", + Lang_CXX, "", Lang_CXX); + + MatchVerifier 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"( @@ -1378,7 +1394,7 @@ TEST_P(ASTImporterTestBase, ShouldImportImplicitCXXRecordDecl) { TEST_P( ASTImporterTestBase, - DISABLED_ShouldImportImplicitCXXRecordDeclOfClassTemplateSpecializationDecl) { + ShouldImportImplicitCXXRecordDeclOfClassTemplateSpecializationDecl) { Decl *From, *To; std::tie(From, To) = getImportedDecl( R"(