summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaStmt.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-06-05 05:14:41 +0000
committerDouglas Gregor <dgregor@apple.com>2011-06-05 05:14:41 +0000
commit7f139d8103c432123ec62c7b74d04d4360c9c86b (patch)
tree535ee415e61d54c66684dbeaa552a1f76ea3549c /clang/lib/Sema/SemaStmt.cpp
parent0aa91e0a666003b7b48d80cd65146ba3cf752310 (diff)
downloadbcm5719-llvm-7f139d8103c432123ec62c7b74d04d4360c9c86b.tar.gz
bcm5719-llvm-7f139d8103c432123ec62c7b74d04d4360c9c86b.zip
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. llvm-svn: 132658
Diffstat (limited to 'clang/lib/Sema/SemaStmt.cpp')
-rw-r--r--clang/lib/Sema/SemaStmt.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 1ecb4196b9d..d3a22cdbb98 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/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;
OpenPOWER on IntegriCloud