diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index 0604470c1dcd..97cad60a19fe 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -762,11 +762,15 @@ Sema::ActOnReturnStmt(SourceLocation ReturnLoc, ExprTy *rex) { unsigned D = diag::ext_return_has_expr; if (RetValExp->getType()->isVoidType()) D = diag::ext_return_has_void_expr; - NamedDecl *CurDecl = getCurFunctionOrMethodDecl(); - Diag(ReturnLoc, D) - << CurDecl->getDeclName() << isa(CurDecl) - << RetValExp->getSourceRange(); + // return (some void expression); is legal in C++. + if (D != diag::ext_return_has_void_expr || + !getLangOptions().CPlusPlus) { + NamedDecl *CurDecl = getCurFunctionOrMethodDecl(); + Diag(ReturnLoc, D) + << CurDecl->getDeclName() << isa(CurDecl) + << RetValExp->getSourceRange(); + } } return new ReturnStmt(ReturnLoc, RetValExp); } diff --git a/clang/test/SemaCXX/statements.cpp b/clang/test/SemaCXX/statements.cpp new file mode 100644 index 000000000000..bfd8af5fa978 --- /dev/null +++ b/clang/test/SemaCXX/statements.cpp @@ -0,0 +1,5 @@ +// RUN: clang %s -fsyntax-only -pedantic + +void foo() { + return foo(); +}