diff options
author | Douglas Gregor <dgregor@apple.com> | 2011-06-05 05:14:41 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2011-06-05 05:14:41 +0000 |
commit | bc3e64f37fe2c68ab4bfcedf6f428e0198f2e349 (patch) | |
tree | 76c5d1c4ad904126364bdd3b91f46f86dda34a3f /lib/Sema/SemaStmt.cpp | |
parent | 6a576ab708d3aa7d40e5d867ab1de5d3cb507553 (diff) |
Allow block returns in C++ with the form
return <expression> ;
in blocks with a 'void' result type, so long as <expression> has type
'void'. This follows the rules for C++ functions.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@132658 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaStmt.cpp')
-rw-r--r-- | lib/Sema/SemaStmt.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index 1ecb4196b9..d3a22cdbb9 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -1617,13 +1617,17 @@ Sema::ActOnBlockReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp) { // compatibility to worry about here. ReturnStmt *Result = 0; if (CurBlock->ReturnType->isVoidType()) { - if (RetValExp) { + if (RetValExp && !RetValExp->isTypeDependent() && + (!getLangOptions().CPlusPlus || !RetValExp->getType()->isVoidType())) { Diag(ReturnLoc, diag::err_return_block_has_expr); RetValExp = 0; } Result = new (Context) ReturnStmt(ReturnLoc, RetValExp, 0); } else if (!RetValExp) { - return StmtError(Diag(ReturnLoc, diag::err_block_return_missing_expr)); + if (!CurBlock->ReturnType->isDependentType()) + return StmtError(Diag(ReturnLoc, diag::err_block_return_missing_expr)); + + Result = new (Context) ReturnStmt(ReturnLoc, 0, 0); } else { const VarDecl *NRVOCandidate = 0; |