r291231 - [ObjC] The declarator for a block literal should be a definition

Alex Lorenz via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 6 03:31:12 PST 2017


Author: arphaman
Date: Fri Jan  6 05:31:12 2017
New Revision: 291231

URL: http://llvm.org/viewvc/llvm-project?rev=291231&view=rev
Log:
[ObjC] The declarator for a block literal should be a definition

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

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

Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=291231&r1=291230&r2=291231&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Fri Jan  6 05:31:12 2017
@@ -2751,6 +2751,7 @@ void Parser::ParseBlockId(SourceLocation
 
   // Parse the block-declarator.
   Declarator DeclaratorInfo(DS, Declarator::BlockLiteralContext);
+  DeclaratorInfo.setFunctionDefinitionKind(FDK_Definition);
   ParseDeclarator(DeclaratorInfo);
 
   MaybeParseGNUAttributes(DeclaratorInfo);
@@ -2789,6 +2790,7 @@ ExprResult Parser::ParseBlockLiteralExpr
   // 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()));

Modified: cfe/trunk/test/Sema/warn-strict-prototypes.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-strict-prototypes.m?rev=291231&r1=291230&r2=291231&view=diff
==============================================================================
--- cfe/trunk/test/Sema/warn-strict-prototypes.m (original)
+++ cfe/trunk/test/Sema/warn-strict-prototypes.m Fri Jan  6 05:31:12 2017
@@ -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
   };
 }

Modified: cfe/trunk/test/SemaObjC/block-omitted-return-type.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/block-omitted-return-type.m?rev=291231&r1=291230&r2=291231&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/block-omitted-return-type.m (original)
+++ cfe/trunk/test/SemaObjC/block-omitted-return-type.m Fri Jan  6 05:31:12 2017
@@ -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 at -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;




More information about the cfe-commits mailing list