[cfe-commits] r171921 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaExpr.cpp test/SemaObjCXX/capturing-flexible-array-in-block.mm

Fariborz Jahanian fjahanian at apple.com
Tue Jan 8 16:09:15 PST 2013


Author: fjahanian
Date: Tue Jan  8 18:09:15 2013
New Revision: 171921

URL: http://llvm.org/viewvc/llvm-project?rev=171921&view=rev
Log:
put back diagnostics when flexible members are captured
in lambdas.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/SemaObjCXX/capturing-flexible-array-in-block.mm

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=171921&r1=171920&r2=171921&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Jan  8 18:09:15 2013
@@ -4612,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=171921&r1=171920&r2=171921&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Jan  8 18:09:15 2013
@@ -10762,10 +10762,13 @@
     // Prohibit structs with flexible 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() && IsBlock) {
+      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();
         }

Modified: 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=171921&r1=171920&r2=171921&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjCXX/capturing-flexible-array-in-block.mm (original)
+++ cfe/trunk/test/SemaObjCXX/capturing-flexible-array-in-block.mm Tue Jan  8 18:09:15 2013
@@ -1,7 +1,8 @@
-// RUN: %clang_cc1 -fsyntax-only -fblocks -verify %s
+// RUN: %clang_cc1 -fsyntax-only -fblocks -verify -std=c++11 %s
 // rdar://12655829
 
 void f() {
-  struct { int x; int y[]; } a; // expected-note {{'a' declared here}}
+  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}}
 }





More information about the cfe-commits mailing list