]> granicus.if.org Git - clang/commitdiff
[ASTImporter] Fix ClassTemplateSpecialization in wrong DC
authorGabor Marton <martongabesz@gmail.com>
Fri, 25 May 2018 11:21:24 +0000 (11:21 +0000)
committerGabor Marton <martongabesz@gmail.com>
Fri, 25 May 2018 11:21:24 +0000 (11:21 +0000)
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

lib/AST/ASTImporter.cpp
unittests/AST/ASTImporterTest.cpp

index 7e402722b19d1a33569472ebe11cf668a75e5272..3294eda2367bdca95c861bdcd301eee09ef0d0a2 100644 (file)
@@ -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))
index c95e8fdaf80ab2baa7318f156f02857f04f1e9ec..76ea2594332ecedab243048a3ab2576b51ef0197 100644 (file)
@@ -1214,7 +1214,7 @@ TEST_P(ASTImporterTestBase, TUshouldNotContainTemplatedDeclOfTypeAlias) {
 
 TEST_P(
     ASTImporterTestBase,
-    DISABLED_TUshouldNotContainClassTemplateSpecializationOfImplicitInstantiation) {
+    TUshouldNotContainClassTemplateSpecializationOfImplicitInstantiation) {
 
   Decl *From, *To;
   std::tie(From, To) = getImportedDecl(