]> granicus.if.org Git - clang/commitdiff
This is valid in C++.
authorChris Lattner <sabre@nondot.org>
Thu, 18 Dec 2008 02:03:48 +0000 (02:03 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 18 Dec 2008 02:03:48 +0000 (02:03 +0000)
void foo() { return foo(); }

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61188 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaStmt.cpp
test/SemaCXX/statements.cpp [new file with mode: 0644]

index 0604470c1dcda53cd3310e84d5b716240a30c913..97cad60a19fe745433a670011a0a035a872d6655 100644 (file)
@@ -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<ObjCMethodDecl>(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<ObjCMethodDecl>(CurDecl)
+          << RetValExp->getSourceRange();
+      }
     }
     return new ReturnStmt(ReturnLoc, RetValExp);
   }
diff --git a/test/SemaCXX/statements.cpp b/test/SemaCXX/statements.cpp
new file mode 100644 (file)
index 0000000..bfd8af5
--- /dev/null
@@ -0,0 +1,5 @@
+// RUN: clang %s -fsyntax-only -pedantic
+
+void foo() { 
+  return foo();
+}