Allow void blocks to return witn a void expression in

c-mode to match behavior with void functions in c. Issue
warning with -pedantic. // rdar://11069896

llvm-svn: 153200
This commit is contained in:
Fariborz Jahanian 2012-03-21 16:45:13 +00:00
parent 8ce585f8f1
commit 3ba24bab1c
3 changed files with 13 additions and 5 deletions

View File

@ -5159,7 +5159,7 @@ def ext_return_has_expr : ExtWarn<
"should not return a value">,
DefaultError, InGroup<ReturnType>;
def ext_return_has_void_expr : Extension<
"void %select{function|method}1 %0 should not return void expression">;
"void %select{function|method|block}1 %0 should not return void expression">;
def err_return_init_list : Error<
"%select{void function|void method|constructor|destructor}1 %0 "
"must not return a value">;

View File

@ -1886,8 +1886,13 @@ Sema::ActOnCapScopeReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp) {
!(getLangOpts().CPlusPlus &&
(RetValExp->isTypeDependent() ||
RetValExp->getType()->isVoidType()))) {
Diag(ReturnLoc, diag::err_return_block_has_expr);
RetValExp = 0;
if (!getLangOpts().CPlusPlus &&
RetValExp->getType()->isVoidType())
Diag(ReturnLoc, diag::ext_return_has_void_expr) << "" << 2;
else {
Diag(ReturnLoc, diag::err_return_block_has_expr);
RetValExp = 0;
}
}
} else if (!RetValExp) {
return StmtError(Diag(ReturnLoc, diag::err_block_return_missing_expr));

View File

@ -1,4 +1,4 @@
// RUN: %clang_cc1 -fsyntax-only %s -verify -fblocks
// RUN: %clang_cc1 -pedantic -fsyntax-only %s -verify -fblocks
typedef void (^CL)(void);
@ -130,4 +130,7 @@ void foo7()
int (^NN) (void) = ^{ return cint; };
}
// rdar://11069896
void (^blk)(void) = ^{
return (void)0; // expected-warning {{void block should not return void expression}}
};