From: Gabor Marton Date: Fri, 25 May 2018 11:21:24 +0000 (+0000) Subject: [ASTImporter] Fix ClassTemplateSpecialization in wrong DC X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=296b914eef4627d6dd69fe6b7f3cc743b89ec3f7;p=clang [ASTImporter] Fix ClassTemplateSpecialization in wrong DC Summary: ClassTemplateSpecialization is put in the wrong DeclContex if implicitly instantiated. This patch fixes it. Reviewers: a.sidorin, r.stahl, xazax.hun Subscribers: rnkovacs, dkrupp, cfe-commits Differential Revision: https://reviews.llvm.org/D47058 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@333269 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/ASTImporter.cpp b/lib/AST/ASTImporter.cpp index 7e402722b1..3294eda236 100644 --- a/lib/AST/ASTImporter.cpp +++ b/lib/AST/ASTImporter.cpp @@ -4320,9 +4320,13 @@ Decl *ASTNodeImporter::VisitClassTemplateSpecializationDecl( D2->setTemplateSpecializationKind(D->getTemplateSpecializationKind()); - // Add the specialization to this context. + // Set the context of this specialization/instantiation. D2->setLexicalDeclContext(LexicalDC); - LexicalDC->addDeclInternal(D2); + + // Add to the DC only if it was an explicit specialization/instantiation. + if (D2->isExplicitInstantiationOrSpecialization()) { + LexicalDC->addDeclInternal(D2); + } } Importer.Imported(D, D2); if (D->isCompleteDefinition() && ImportDefinition(D, D2)) diff --git a/unittests/AST/ASTImporterTest.cpp b/unittests/AST/ASTImporterTest.cpp index c95e8fdaf8..76ea259433 100644 --- a/unittests/AST/ASTImporterTest.cpp +++ b/unittests/AST/ASTImporterTest.cpp @@ -1214,7 +1214,7 @@ TEST_P(ASTImporterTestBase, TUshouldNotContainTemplatedDeclOfTypeAlias) { TEST_P( ASTImporterTestBase, - DISABLED_TUshouldNotContainClassTemplateSpecializationOfImplicitInstantiation) { + TUshouldNotContainClassTemplateSpecializationOfImplicitInstantiation) { Decl *From, *To; std::tie(From, To) = getImportedDecl(