summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/ASTImporter.cpp
diff options
context:
space:
mode:
authorGabor Marton <gabor.marton@ericsson.com>2019-07-08 12:49:13 +0000
committerGabor Marton <gabor.marton@ericsson.com>2019-07-08 12:49:13 +0000
commite73805f80eab155e38a83c61710b5186ea2ea04f (patch)
tree58f8c7407f7303807250d9605310907181568e09 /clang/lib/AST/ASTImporter.cpp
parent0752d12c0910ece5041806e5d967ce48039df9f7 (diff)
downloadbcm5719-llvm-e73805f80eab155e38a83c61710b5186ea2ea04f.tar.gz
bcm5719-llvm-e73805f80eab155e38a83c61710b5186ea2ea04f.zip
[ASTImporter] Fix import of lambda in function param
Summary: The current import implementation fails to import the definition of a lambda class if the lambda class is defined in a function param. E.g., the lambda class below will be imported without any methods: ``` template <typename F> void f(F L = [](){}) {} ``` Reviewers: a_sidorin, a.sidorin, shafik Subscribers: rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D64073 llvm-svn: 365315
Diffstat (limited to 'clang/lib/AST/ASTImporter.cpp')
-rw-r--r--clang/lib/AST/ASTImporter.cpp23
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()) {
OpenPOWER on IntegriCloud