From: Argyrios Kyrtzidis Date: Tue, 25 Jan 2011 23:16:33 +0000 (+0000) Subject: Change error "function cannot return array type" -> "blocks cannot return array type... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=98650449dc769dd6217f183c846dcaf9e6f94930;p=clang Change error "function cannot return array type" -> "blocks cannot return array type" when blocks are involved. Addresses rdar://8876238. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124242 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index f33285c7d4..9518ed91bf 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -3381,8 +3381,8 @@ def err_blocks_disable : Error<"blocks support disabled - compile with -fblocks" def err_expected_block_lbrace : Error<"expected '{' 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_block_returning_array_function : Error< + "block cannot return %select{array|function}0 type %1">; // CFString checking diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index c8f7545602..09ebbc085f 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -1621,8 +1621,10 @@ TypeSourceInfo *Sema::GetTypeForDeclarator(Declarator &D, Scope *S, // For conversion functions, we'll diagnose this particular error later. if ((T->isArrayType() || T->isFunctionType()) && (D.getName().getKind() != UnqualifiedId::IK_ConversionFunctionId)) { - Diag(DeclType.Loc, diag::err_func_returning_array_function) - << T->isFunctionType() << T; + unsigned diagID = diag::err_func_returning_array_function; + if (D.getContext() == Declarator::BlockLiteralContext) + diagID = diag::err_block_returning_array_function; + Diag(DeclType.Loc, diagID) << T->isFunctionType() << T; T = Context.IntTy; D.setInvalidType(true); } diff --git a/test/Sema/block-return.c b/test/Sema/block-return.c index 5741fc9c6d..2eb51e79cc 100644 --- a/test/Sema/block-return.c +++ b/test/Sema/block-return.c @@ -97,7 +97,7 @@ bptr foo5(int j) { } int (*funcptr3[5])(long); -int sz8 = sizeof(^int (*[5])(long) {return funcptr3;}); // expected-error {{function cannot return array type}} expected-warning {{incompatible pointer to integer conversion}} +int sz8 = sizeof(^int (*[5])(long) {return funcptr3;}); // expected-error {{block cannot return array type}} expected-warning {{incompatible pointer to integer conversion}} void foo6() { int (^b)(int) __attribute__((noreturn));