diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2018-10-19 19:01:34 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2018-10-19 19:01:34 +0000 |
commit | b3d203ff7f308cc5675f095654d0cda905bf95bf (patch) | |
tree | 827f58b9968e6a725ea2d02434ceea1869981c9b /clang/lib/Sema/SemaInit.cpp | |
parent | 36f62c066a8cd97a0b3459eec11d929ec875c941 (diff) | |
download | bcm5719-llvm-b3d203ff7f308cc5675f095654d0cda905bf95bf.tar.gz bcm5719-llvm-b3d203ff7f308cc5675f095654d0cda905bf95bf.zip |
PR24164, PR39336: init-captures are not distinct full-expressions.
Rather, they are subexpressions of the enclosing lambda-expression, and
any temporaries in them are destroyed at the end of that
full-expression, or when the corresponding lambda-expression is
destroyed if they are lifetime-extended.
llvm-svn: 344801
Diffstat (limited to 'clang/lib/Sema/SemaInit.cpp')
-rw-r--r-- | clang/lib/Sema/SemaInit.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index 958dd66612c..71f3c4e34b5 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -6786,6 +6786,20 @@ static void visitLocalsRetainedByInitializer(IndirectLocalPath &Path, return; } + // The lifetime of an init-capture is that of the closure object constructed + // by a lambda-expression. + if (auto *LE = dyn_cast<LambdaExpr>(Init)) { + for (Expr *E : LE->capture_inits()) { + if (!E) + continue; + if (E->isGLValue()) + visitLocalsRetainedByReferenceBinding(Path, E, RK_ReferenceBinding, + Visit); + else + visitLocalsRetainedByInitializer(Path, E, Visit, true); + } + } + if (isa<CallExpr>(Init) || isa<CXXConstructExpr>(Init)) return visitLifetimeBoundArguments(Path, Init, Visit); |