]> granicus.if.org Git - clang/commitdiff
Don't allow blocks to be declared as returning an array. Radar 6441502
authorMike Stump <mrs@apple.com>
Tue, 28 Apr 2009 01:10:27 +0000 (01:10 +0000)
committerMike Stump <mrs@apple.com>
Tue, 28 Apr 2009 01:10:27 +0000 (01:10 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70277 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaExpr.cpp
test/Sema/block-return.c

index e115703a95e5729b3b211d8c58f28e30498f5eb9..fb1820d8ecba3089f44cc974f37b5a9519d12466 100644 (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">;
index f2f8ae5797c776d5529d060f8cb4de0acada35bc..045fa180e65c016f23ec2a2acfba499375389103 100644 (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);
index e6101d176f895ae0b157bc972f73604f42465f40..4b0dbb0b013faa39cde10260ee2cd7c4706d741e 100644 (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}}