diff options
Diffstat (limited to 'clang/lib/AST/ASTImporter.cpp')
-rw-r--r-- | clang/lib/AST/ASTImporter.cpp | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index cc4cb16794f..55d414e4e57 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -1708,8 +1708,18 @@ static Error setTypedefNameForAnonDecl(TagDecl *From, TagDecl *To, Error ASTNodeImporter::ImportDefinition( RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind) { if (To->getDefinition() || To->isBeingDefined()) { - if (Kind == IDK_Everything) - return ImportDeclContext(From, /*ForceImport=*/true); + if (Kind == IDK_Everything || + // In case of lambdas, the class already has a definition ptr set, but + // the contained decls are not imported yet. Also, isBeingDefined was + // set in CXXRecordDecl::CreateLambda. We must import the contained + // decls here and finish the definition. + (To->isLambda() && shouldForceImportDeclContext(Kind))) { + Error Result = ImportDeclContext(From, /*ForceImport=*/true); + // Finish the definition of the lambda, set isBeingDefined to false. + if (To->isLambda()) + To->completeDefinition(); + return Result; + } return Error::success(); } @@ -7422,19 +7432,10 @@ ExpectedStmt ASTNodeImporter::VisitLambdaExpr(LambdaExpr *E) { return ToClassOrErr.takeError(); CXXRecordDecl *ToClass = *ToClassOrErr; - // 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()) - if (Error Err = ImportDeclContext(FromClass, /*ForceImport = */ true)) - return std::move(Err); - auto ToCallOpOrErr = import(E->getCallOperator()); if (!ToCallOpOrErr) return ToCallOpOrErr.takeError(); - ToClass->completeDefinition(); - SmallVector<LambdaCapture, 8> ToCaptures; ToCaptures.reserve(E->capture_size()); for (const auto &FromCapture : E->captures()) { |