Просмотр исходного кода

[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
Gabor Marton 7 лет назад
Родитель
Сommit
296b914eef
2 измененных файлов с 7 добавлено и 3 удалено
  1. 6 2
      lib/AST/ASTImporter.cpp
  2. 1 1
      unittests/AST/ASTImporterTest.cpp

+ 6 - 2
lib/AST/ASTImporter.cpp

@@ -4320,9 +4320,13 @@ Decl *ASTNodeImporter::VisitClassTemplateSpecializationDecl(
 
 
     D2->setTemplateSpecializationKind(D->getTemplateSpecializationKind());
     D2->setTemplateSpecializationKind(D->getTemplateSpecializationKind());
 
 
-    // Add the specialization to this context.
+    // Set the context of this specialization/instantiation.
     D2->setLexicalDeclContext(LexicalDC);
     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);
   Importer.Imported(D, D2);
   if (D->isCompleteDefinition() && ImportDefinition(D, D2))
   if (D->isCompleteDefinition() && ImportDefinition(D, D2))

+ 1 - 1
unittests/AST/ASTImporterTest.cpp

@@ -1214,7 +1214,7 @@ TEST_P(ASTImporterTestBase, TUshouldNotContainTemplatedDeclOfTypeAlias) {
 
 
 TEST_P(
 TEST_P(
     ASTImporterTestBase,
     ASTImporterTestBase,
-    DISABLED_TUshouldNotContainClassTemplateSpecializationOfImplicitInstantiation) {
+    TUshouldNotContainClassTemplateSpecializationOfImplicitInstantiation) {
 
 
   Decl *From, *To;
   Decl *From, *To;
   std::tie(From, To) = getImportedDecl(
   std::tie(From, To) = getImportedDecl(