Skip to content

Commit c7dc1a2

Browse files
committedJan 6, 2017
[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 llvm-svn: 291231
1 parent 01dd2f7 commit c7dc1a2

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed
 

‎clang/lib/Parse/ParseExpr.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -2751,6 +2751,7 @@ void Parser::ParseBlockId(SourceLocation CaretLoc) {
27512751

27522752
// Parse the block-declarator.
27532753
Declarator DeclaratorInfo(DS, Declarator::BlockLiteralContext);
2754+
DeclaratorInfo.setFunctionDefinitionKind(FDK_Definition);
27542755
ParseDeclarator(DeclaratorInfo);
27552756

27562757
MaybeParseGNUAttributes(DeclaratorInfo);
@@ -2789,6 +2790,7 @@ ExprResult Parser::ParseBlockLiteralExpression() {
27892790
// Parse the return type if present.
27902791
DeclSpec DS(AttrFactory);
27912792
Declarator ParamInfo(DS, Declarator::BlockLiteralContext);
2793+
ParamInfo.setFunctionDefinitionKind(FDK_Definition);
27922794
// FIXME: Since the return type isn't actually parsed, it can't be used to
27932795
// fill ParamInfo with an initial valid range, so do it manually.
27942796
ParamInfo.SetSourceRange(SourceRange(Tok.getLocation(), Tok.getLocation()));

‎clang/test/Sema/warn-strict-prototypes.m

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ void foo() {
1414
void (^block)() = // expected-warning {{this function declaration is not a prototype}}
1515
^void(int arg) { // no warning
1616
};
17-
void (^block2)(void) = // no warning
18-
^void() { // expected-warning {{this function declaration is not a prototype}}
17+
void (^block2)(void) = ^void() { // no warning
18+
};
19+
void (^block3)(void) = ^ { // no warning
1920
};
2021
}

‎clang/test/SemaObjC/block-omitted-return-type.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ - (void)test
2424
return;
2525
};
2626
void (^simpleBlock5)() = ^ const void { //expected-error {{incompatible block pointer types initializing 'void (^)()' with an expression of type 'const void (^)(void)'}}
27-
return;
27+
return; // expected-warning@-1 {{function cannot return qualified void type 'const void'}}
2828
};
2929
void (^simpleBlock6)() = ^ const (void) { //expected-warning {{'const' qualifier on omitted return type '<dependent type>' has no effect}}
3030
return;

0 commit comments

Comments
 (0)