From: Fariborz Jahanian Date: Wed, 21 Mar 2012 16:45:13 +0000 (+0000) Subject: Allow void blocks to return witn a void expression in X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4e648e4770d85febaf15ad8b7bad458bd7338ae2;p=clang 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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@153200 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 1efa4f2f17..2ce1e895dc 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -5159,7 +5159,7 @@ def ext_return_has_expr : ExtWarn< "should not return a value">, DefaultError, InGroup; 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">; diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index ef453f5c6a..333f6dd255 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -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)); diff --git a/test/Sema/block-return.c b/test/Sema/block-return.c index e8c651652b..67bc5c7dfe 100644 --- a/test/Sema/block-return.c +++ b/test/Sema/block-return.c @@ -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}} +};