[cfe-commits] r171912 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaExpr.cpp test/SemaObjCXX/capturing-flexible-array-in-block.mm
Eli Friedman
eli.friedman at gmail.com
Tue Jan 8 15:29:21 PST 2013
On Tue, Jan 8, 2013 at 3:17 PM, Fariborz Jahanian <fjahanian at apple.com> wrote:
> Author: fjahanian
> Date: Tue Jan 8 17:17:51 2013
> New Revision: 171912
>
> URL: http://llvm.org/viewvc/llvm-project?rev=171912&view=rev
> Log:
> objectiveC blocks: It is impractical to capture
> struct variables with flexiable array members in
> blocks (and lambdas). Issue error instead of
> crashing in IRGen. // rdar://12655829
>
> Added:
> cfe/trunk/test/SemaObjCXX/capturing-flexible-array-in-block.mm
> Modified:
> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> cfe/trunk/lib/Sema/SemaExpr.cpp
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=171912&r1=171911&r2=171912&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Jan 8 17:17:51 2013
> @@ -4224,6 +4224,9 @@
> def err_ref_non_value : Error<"%0 does not refer to a value">;
> def err_ref_vm_type : Error<
> "cannot refer to declaration with a variably modified type inside block">;
> +def err_ref_flexarray_type : Error<
> + "cannot refer to declaration of structure variable with flexible array member "
> + "inside block">;
> def err_ref_array_type : Error<
> "cannot refer to declaration with an array type inside block">;
> def err_property_not_found : Error<
> @@ -4609,6 +4612,9 @@
> def err_lambda_capture_vm_type : Error<
> "variable %0 with variably modified type cannot be captured in "
> "a lambda expression">;
> + def err_lambda_capture_flexarray_type : Error<
> + "variable %0 with flexible array member cannot be captured in "
> + "a lambda expression">;
> def err_lambda_impcap : Error<
> "variable %0 cannot be implicitly captured in a lambda with no "
> "capture-default specified">;
>
> Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=171912&r1=171911&r2=171912&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Jan 8 17:17:51 2013
> @@ -10759,7 +10759,22 @@
> }
> return true;
> }
> -
> + // Prohibit prohibit structs with flexisble array members too.
> + // We cannot capture what is in the tail end of the struct.
> + if (const RecordType *VTTy = Var->getType()->getAs<RecordType>()) {
> + if (VTTy->getDecl()->hasFlexibleArrayMember()) {
> + if (BuildAndDiagnose) {
> + if (IsBlock)
> + Diag(Loc, diag::err_ref_flexarray_type);
> + else
> + Diag(Loc, diag::err_lambda_capture_flexarray_type)
> + << Var->getDeclName();
> + Diag(Var->getLocation(), diag::note_previous_decl)
> + << Var->getDeclName();
> + }
> + return true;
> + }
> + }
> // Lambdas are not allowed to capture __block variables; they don't
> // support the expected semantics.
> if (IsLambda && HasBlocksAttr) {
>
> Added: cfe/trunk/test/SemaObjCXX/capturing-flexible-array-in-block.mm
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/capturing-flexible-array-in-block.mm?rev=171912&view=auto
> ==============================================================================
> --- cfe/trunk/test/SemaObjCXX/capturing-flexible-array-in-block.mm (added)
> +++ cfe/trunk/test/SemaObjCXX/capturing-flexible-array-in-block.mm Tue Jan 8 17:17:51 2013
> @@ -0,0 +1,9 @@
> +// RUN: %clang_cc1 -fsyntax-only -fblocks -verify -std=c++11 %s
> +// rdar://12655829
> +
> +void f() {
> + struct { int x; int y[]; } a; // expected-note 2 {{'a' declared here}}
> + ^{return a.x;}(); // expected-error {{cannot refer to declaration of structure variable with flexible array member inside block}}
> +
> + [] {return a.x;}(); // expected-error {{variable 'a' with flexible array member cannot be captured in a lambda expression}}
> +}
We can do whatever we want with blocks, but the C++11 standard doesn't
allow us to reject this construct for lambda expressions.
-Eli
More information about the cfe-commits
mailing list