]> granicus.if.org Git - clang/commitdiff
Downgrade an error about "return in a no-return function" from being
authorChris Lattner <sabre@nondot.org>
Sun, 31 May 2009 19:32:13 +0000 (19:32 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 31 May 2009 19:32:13 +0000 (19:32 +0000)
an error to being a warning that defaults to error.  If you want this to
be a warning, you have to explicitly pass -Winvalid-noreturn to clang to
map it back to a warning.

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

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaStmt.cpp
test/Sema/attr-noreturn.c

index 732386fa140a809bb0473251ce94fbcaaf1e3748..672e473678dd574798743ceccd782c94c60e32ef 100644 (file)
@@ -1736,8 +1736,9 @@ def ext_return_has_expr : ExtWarn<
   InGroup<ReturnType>;
 def ext_return_has_void_expr : Extension<
   "void %select{function|method}1 %0 should not return void expression">;
-def err_noreturn_function_has_return_expr : Error<
-  "function %0 declared 'noreturn' should not return">;
+def warn_noreturn_function_has_return_expr : Warning<
+  "function %0 declared 'noreturn' should not return">, DefaultError,
+  InGroup<DiagGroup<"invalid-noreturn">>;
 def err_noreturn_block_has_return_expr : Error<
   "block declared 'noreturn' should not return">;
 def err_block_on_nonlocal : Error<
index 879d84e36c677f6ec86dad36686f51db4f1fd5b8..15262e9c3ac2ca74c53569cf5721a9badb9c178d 100644 (file)
@@ -834,11 +834,9 @@ Sema::ActOnReturnStmt(SourceLocation ReturnLoc, FullExprArg rex) {
   QualType FnRetType;
   if (const FunctionDecl *FD = getCurFunctionDecl()) {
     FnRetType = FD->getResultType();
-    if (FD->hasAttr<NoReturnAttr>()) {
-      Diag(ReturnLoc, diag::err_noreturn_function_has_return_expr)
+    if (FD->hasAttr<NoReturnAttr>())
+      Diag(ReturnLoc, diag::warn_noreturn_function_has_return_expr)
         << getCurFunctionOrMethodDecl()->getDeclName();
-      return StmtError();
-    }
   } else if (ObjCMethodDecl *MD = getCurMethodDecl())
     FnRetType = MD->getResultType();
   else // If we don't have a function/method context, bail.
index 1335c765b3d2c035dd0b4eb5644145dd06395935..d1417f093ffb9d21728bba830c387f9b43aae197 100644 (file)
@@ -14,8 +14,14 @@ int g0 __attribute__((noreturn)); // expected-warning {{'noreturn' attribute onl
 int f2() __attribute__((noreturn(1, 2))); // expected-error {{attribute requires 0 argument(s)}}
 
 void f3() __attribute__((noreturn));
-
 void f3() {
   return;  // expected-error {{function 'f3' declared 'noreturn' should not return}}
 }
 
+#pragma clang diagnostic warning "-Winvalid-noreturn"
+
+void f4() __attribute__((noreturn));
+void f4() {
+  return;  // expected-warning {{function 'f4' declared 'noreturn' should not return}}
+}
+