Don't allow blocks to be declared as returning an array. Radar 6441502

llvm-svn: 70277
This commit is contained in:
Mike Stump 2009-04-28 01:10:27 +00:00
parent 56f2987a87
commit d456c48568
3 changed files with 11 additions and 0 deletions

View File

@ -1551,6 +1551,8 @@ def err_goto_in_block : Error<
"goto not allowed in block literal">;
def err_return_in_block_expression : Error<
"return not allowed in block expression literal">;
def err_block_returns_array : Error<
"block declared as returning an array">;
def err_ret_local_block : Error<
"returning block that lives on the local stack">;

View File

@ -4726,6 +4726,12 @@ void Sema::ActOnBlockArguments(Declarator &ParamInfo, Scope *CurScope) {
|| ParamInfo.getTypeObject(0).Kind != DeclaratorChunk::Function) {
QualType T = GetTypeForDeclarator(ParamInfo, CurScope);
if (T->isArrayType()) {
Diag(ParamInfo.getSourceRange().getBegin(),
diag::err_block_returns_array);
return;
}
// The parameter list is optional, if there was none, assume ().
if (!T->isFunctionType())
T = Context.getFunctionType(T, NULL, 0, 0, 0);

View File

@ -92,3 +92,6 @@ bptr foo5(int j) {
return ^{ ^{ i=0; }(); }; // expected-error {{returning block that lives on the local stack}}
return ^{ i=0; }; // expected-error {{returning block that lives on the local stack}}
}
int (*funcptr3[5])(long);
int sz8 = sizeof(^int (*[5])(long) {return funcptr3;}); // expected-error {{block declared as returning an array}}