From a716a345276c5868d966707b8c23c325be769d19 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Tue, 8 Jan 2013 23:17:51 +0000 Subject: 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 llvm-svn: 171912 --- clang/lib/Sema/SemaExpr.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'clang/lib/Sema') diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 1704de6e95e..b5630ecb121 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -10759,7 +10759,22 @@ bool Sema::tryCaptureVariable(VarDecl *Var, SourceLocation Loc, } 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()) { + 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) { -- cgit v1.2.3