aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2013-01-09 00:09:15 +0000
committerFariborz Jahanian <fjahanian@apple.com>2013-01-09 00:09:15 +0000
commite178e70e14380cf8828a307f912fcdbd3882b752 (patch)
tree740eea36d1c92c8099b1725853bf2a02005927c8
parent080dc528c7016a107b94430b84cee6ad33e09155 (diff)
put back diagnostics when flexible members are captured
in lambdas. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171921 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Basic/DiagnosticSemaKinds.td3
-rw-r--r--lib/Sema/SemaExpr.cpp5
-rw-r--r--test/SemaObjCXX/capturing-flexible-array-in-block.mm5
3 files changed, 10 insertions, 3 deletions
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td
index 691da35451..4d8f267098 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4612,6 +4612,9 @@ let CategoryName = "Lambda Issue" in {
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">;
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 5b7a39674b..96196e0693 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -10762,10 +10762,13 @@ bool Sema::tryCaptureVariable(VarDecl *Var, SourceLocation Loc,
// 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();
}
diff --git a/test/SemaObjCXX/capturing-flexible-array-in-block.mm b/test/SemaObjCXX/capturing-flexible-array-in-block.mm
index 6ffe350135..d7d888564c 100644
--- a/test/SemaObjCXX/capturing-flexible-array-in-block.mm
+++ b/test/SemaObjCXX/capturing-flexible-array-in-block.mm
@@ -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}}
}