r354120 - [ASTImporter] Import every Decl in lambda record

Gabor Marton via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 15 04:04:05 PST 2019


Author: martong
Date: Fri Feb 15 04:04:05 2019
New Revision: 354120

URL: http://llvm.org/viewvc/llvm-project?rev=354120&view=rev
Log:
[ASTImporter] Import every Decl in lambda record

Summary:
Previously only the fields were imported. Now every Decl is imported.
This way the destructor decl is not missing after import.

Patch by balazske (Balázs Kéri)

Reviewers: a.sidorin, shafik

Reviewed By: shafik

Subscribers: balazske, cfe-commits, Szelethus, martong, dkrupp

Tags: #clang

Differential Revision: https://reviews.llvm.org/D57740

Modified:
    cfe/trunk/lib/AST/ASTImporter.cpp
    cfe/trunk/unittests/AST/ASTImporterTest.cpp

Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=354120&r1=354119&r2=354120&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Fri Feb 15 04:04:05 2019
@@ -7393,13 +7393,9 @@ ExpectedStmt ASTNodeImporter::VisitLambd
   // NOTE: lambda classes are created with BeingDefined flag set up.
   // It means that ImportDefinition doesn't work for them and we should fill it
   // manually.
-  if (ToClass->isBeingDefined()) {
-    for (auto FromField : FromClass->fields()) {
-      auto ToFieldOrErr = import(FromField);
-      if (!ToFieldOrErr)
-        return ToFieldOrErr.takeError();
-    }
-  }
+  if (ToClass->isBeingDefined())
+    if (Error Err = ImportDeclContext(FromClass, /*ForceImport = */ true))
+      return std::move(Err);
 
   auto ToCallOpOrErr = import(E->getCallOperator());
   if (!ToCallOpOrErr)

Modified: cfe/trunk/unittests/AST/ASTImporterTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/ASTImporterTest.cpp?rev=354120&r1=354119&r2=354120&view=diff
==============================================================================
--- cfe/trunk/unittests/AST/ASTImporterTest.cpp (original)
+++ cfe/trunk/unittests/AST/ASTImporterTest.cpp Fri Feb 15 04:04:05 2019
@@ -2709,6 +2709,26 @@ TEST_P(ImportFunctions, ImportFunctionFr
             2u);
 }
 
+TEST_P(ImportFunctions, ImportImplicitFunctionsInLambda) {
+  Decl *FromTU = getTuDecl(
+      R"(
+      void foo() {
+        (void)[]() { ; };
+      }
+      )",
+      Lang_CXX11);
+  auto *FromD = FirstDeclMatcher<FunctionDecl>().match(
+      FromTU, functionDecl(hasName("foo")));
+  auto *ToD = Import(FromD, Lang_CXX);
+  EXPECT_TRUE(ToD);
+  CXXRecordDecl *LambdaRec =
+      cast<LambdaExpr>(cast<CStyleCastExpr>(
+                           *cast<CompoundStmt>(ToD->getBody())->body_begin())
+                           ->getSubExpr())
+          ->getLambdaClass();
+  EXPECT_TRUE(LambdaRec->getDestructor());
+}
+
 struct ImportFriendFunctions : ImportFunctions {};
 
 TEST_P(ImportFriendFunctions, ImportFriendFunctionRedeclChainProto) {




More information about the cfe-commits mailing list