]> granicus.if.org Git - clang/commitdiff
[ObjC] The declarator for a block literal should be a definition
authorAlex Lorenz <arphaman@gmail.com>
Fri, 6 Jan 2017 11:31:12 +0000 (11:31 +0000)
committerAlex Lorenz <arphaman@gmail.com>
Fri, 6 Jan 2017 11:31:12 +0000 (11:31 +0000)
This change avoids the -Wstrict-prototypes warning for block literals with an
empty argument list or without argument lists.

rdar://15060615

Differential Revision: https://reviews.llvm.org/D28296

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@291231 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Parse/ParseExpr.cpp
test/Sema/warn-strict-prototypes.m
test/SemaObjC/block-omitted-return-type.m

index caf2320f8fc1cfb9b1098f484674a346b80976ea..55b5ff498574c9b3b067eed277cacf804917b229 100644 (file)
@@ -2751,6 +2751,7 @@ void Parser::ParseBlockId(SourceLocation CaretLoc) {
 
   // Parse the block-declarator.
   Declarator DeclaratorInfo(DS, Declarator::BlockLiteralContext);
+  DeclaratorInfo.setFunctionDefinitionKind(FDK_Definition);
   ParseDeclarator(DeclaratorInfo);
 
   MaybeParseGNUAttributes(DeclaratorInfo);
@@ -2789,6 +2790,7 @@ ExprResult Parser::ParseBlockLiteralExpression() {
   // Parse the return type if present.
   DeclSpec DS(AttrFactory);
   Declarator ParamInfo(DS, Declarator::BlockLiteralContext);
+  ParamInfo.setFunctionDefinitionKind(FDK_Definition);
   // FIXME: Since the return type isn't actually parsed, it can't be used to
   // fill ParamInfo with an initial valid range, so do it manually.
   ParamInfo.SetSourceRange(SourceRange(Tok.getLocation(), Tok.getLocation()));
index cbb01a1f7b2156dbd3c2b7c1f9af72bc7fe7ad0d..4567dab01930fe57f80e848b74cd804219e7fbeb 100644 (file)
@@ -14,7 +14,8 @@ void foo() {
   void (^block)() = // expected-warning {{this function declaration is not a prototype}}
                     ^void(int arg) { // no warning
   };
-  void (^block2)(void) = // no warning
-                         ^void() { // expected-warning {{this function declaration is not a prototype}}
+  void (^block2)(void) = ^void() { // no warning
+  };
+  void (^block3)(void) = ^ { // no warning
   };
 }
index 20e32e01865ef6ac9851997f05a4670b684f02a0..93d5e05ea2824f69a520c0703c9d79e8decc256e 100644 (file)
@@ -24,7 +24,7 @@
     return;
   };
   void (^simpleBlock5)() = ^ const void { //expected-error {{incompatible block pointer types initializing 'void (^)()' with an expression of type 'const void (^)(void)'}}
-    return;
+    return; // expected-warning@-1 {{function cannot return qualified void type 'const void'}}
   };
   void (^simpleBlock6)() = ^ const (void) { //expected-warning {{'const' qualifier on omitted return type '<dependent type>' has no effect}}
     return;