static ExprResult captureInLambda(Sema &S, LambdaScopeInfo *LSI,
VarDecl *Var, QualType FieldType,
QualType DeclRefType,
- SourceLocation Loc) {
+ SourceLocation Loc,
+ bool RefersToEnclosingLocal) {
CXXRecordDecl *Lambda = LSI->Lambda;
// Build the non-static data member.
// C++ [expr.prim.labda]p12:
// An entity captured by a lambda-expression is odr-used (3.2) in
// the scope containing the lambda-expression.
- Expr *Ref = new (S.Context) DeclRefExpr(Var, true, DeclRefType,
- VK_LValue, Loc);
+ Expr *Ref = new (S.Context) DeclRefExpr(Var, RefersToEnclosingLocal,
+ DeclRefType, VK_LValue, Loc);
Var->setReferenced(true);
Var->setUsed(true);
Expr *CopyExpr = 0;
if (BuildAndDiagnose) {
ExprResult Result = captureInLambda(*this, LSI, Var, CaptureType,
- DeclRefType, Loc);
+ DeclRefType, Loc,
+ I == N-1);
if (!Result.isInvalid())
CopyExpr = Result.take();
}
--- /dev/null
+// RUN: %clang_cc1 -std=c++11 -fblocks -emit-llvm -o - -triple x86_64-apple-darwin11.3 %s | FileCheck %s
+
+namespace PR12746 {
+ // CHECK: define zeroext i1 @_ZN7PR127462f1EPi
+ bool f1(int *x) {
+ // CHECK: store i8* bitcast (i1 (i8*)* @__f1_block_invoke_0 to i8*)
+ bool (^outer)() = ^ {
+ auto inner = [&]() -> bool {
+ return x == 0;
+ };
+ return inner();
+ };
+ return outer();
+ }
+
+ // CHECK: define internal zeroext i1 @__f1_block_invoke_0
+ // CHECK: call zeroext i1 @"_ZNK7PR127462f119__f1_block_invoke_03$_0clEv"
+
+ bool f2(int *x) {
+ auto outer = [&]() -> bool {
+ bool (^inner)() = ^ {
+ return x == 0;
+ };
+ return inner();
+ };
+ return outer();
+ }
+}
+