[PATCH] D47057: [ASTImporter] Fix missing implict CXXRecordDecl in ClassTemplateSpecializationDecl

Gabor Marton via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue May 22 06:35:40 PDT 2018


martong updated this revision to Diff 147994.
martong marked an inline comment as done.
martong added a comment.

- Add new test case for simple CXXRecordDecl
- Add comment about ClassTemplateSpecializationDecl implicit CXXRecordDecl


Repository:
  rC Clang

https://reviews.llvm.org/D47057

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


Index: unittests/AST/ASTImporterTest.cpp
===================================================================
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -1352,6 +1352,22 @@
   Decl *From, *To;
   std::tie(From, To) = getImportedDecl(
       R"(
+      struct declToImport {
+      };
+      )",
+      Lang_CXX, "", Lang_CXX);
+
+  MatchVerifier<Decl> 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"(
       template <typename U>
       struct declToImport {
       };
@@ -1367,7 +1383,7 @@
 
 TEST_P(
     ASTImporterTestBase,
-    DISABLED_ShouldImportImplicitCXXRecordDeclOfClassTemplateSpecializationDecl) {
+    ShouldImportImplicitCXXRecordDeclOfClassTemplateSpecializationDecl) {
   Decl *From, *To;
   std::tie(From, To) = getImportedDecl(
       R"(
Index: lib/AST/ASTImporter.cpp
===================================================================
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -1959,14 +1959,19 @@
   // but this particular declaration is not that definition, import the
   // definition and map to that.
   TagDecl *Definition = D->getDefinition();
-  if (Definition && Definition != D) {
+  if (!D->isImplicit() /*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.*/
+      && Definition && Definition != D) {
     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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47057.147994.patch
Type: text/x-patch
Size: 2163 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180522/0078bd83/attachment.bin>


More information about the cfe-commits mailing list