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 f33285c..9518ed9 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3381,8 +3381,8 @@
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 c8f7545..09ebbc0 100644
--- a/lib/Sema/SemaType.cpp
+++ b/lib/Sema/SemaType.cpp
@@ -1621,8 +1621,10 @@
// 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 5741fc9..2eb51e7 100644
--- a/test/Sema/block-return.c
+++ b/test/Sema/block-return.c
@@ -97,7 +97,7 @@
}
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));