Index: lib/AST/ASTImporter.cpp =================================================================== --- lib/AST/ASTImporter.cpp +++ lib/AST/ASTImporter.cpp @@ -4298,9 +4298,13 @@ 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)) Index: unittests/AST/ASTImporterTest.cpp =================================================================== --- unittests/AST/ASTImporterTest.cpp +++ unittests/AST/ASTImporterTest.cpp @@ -1246,7 +1246,7 @@ TEST_P( ASTImporterTestBase, - DISABLED_TUshouldNotContainClassTemplateSpecializationOfImplicitInstantiation) { + TUshouldNotContainClassTemplateSpecializationOfImplicitInstantiation) { Decl *From, *To; std::tie(From, To) = getImportedDecl(