"%0 cannot be captured because it does not have automatic storage duration">;
def err_implicit_this_capture : Error<
"'this' cannot be implicitly captured in this context">;
-
+def err_lambda_capture_block : Error<
+ "__block variable %0 cannot be captured in a lambda">;
+
def err_operator_arrow_circular : Error<
"circular pointer delegation detected">;
def err_pseudo_dtor_base_not_scalar : Error<
continue;
}
- // FIXME: This is completely wrong for nested captures and variables
- // with a non-trivial constructor.
- // FIXME: We should refuse to capture __block variables.
+ if (Var->hasAttr<BlocksAttr>()) {
+ Diag(C->Loc, diag::err_lambda_capture_block) << C->Id;
+ Diag(Var->getLocation(), diag::note_previous_decl) << C->Id;
+ continue;
+ }
+
+ // FIXME: If this is capture by copy, make sure that we can in fact copy
+ // the variable.
Captures.push_back(LambdaScopeInfo::Capture(Var, C->Kind == LCK_ByRef,
/*isNested*/false, 0));
CaptureMap[Var] = Captures.size();
--- /dev/null
+// RUN: %clang_cc1 -std=c++11 -fblocks %s -verify
+
+void block_capture_errors() {
+ __block int var; // expected-note 2{{'var' declared here}}
+ (void)[var] { }; // expected-error{{__block variable 'var' cannot be captured in a lambda}} \
+ // expected-error{{lambda expressions are not supported yet}}
+
+ // FIXME: this should produce the same error as above
+ (void)[=] { var = 17; }; // expected-error{{reference to local variable 'var' declared in enclosed function 'block_capture_errors'}} \
+ // expected-error{{lambda expressions are not supported yet}}
+}