[PATCH] NoReturn Warning: Non-Void Return Type
Michael Bao
mike.h.bao at gmail.com
Fri Jan 3 13:09:05 PST 2014
Hm, sorry for the spam. Not really sure how Phabricator works yet :)
But here is the updated diff (plain text in the email).
Index: include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- include/clang/Basic/DiagnosticSemaKinds.td (revision 198292)
+++ include/clang/Basic/DiagnosticSemaKinds.td (working copy)
@@ -6462,6 +6462,9 @@
def warn_falloff_noreturn_function : Warning<
"function declared 'noreturn' should not return">,
InGroup<InvalidNoreturn>;
+def warn_noreturn_function_has_nonvoid_type : Warning<
+ "function %0 declared 'noreturn' should not have a non-void return type">,
+ InGroup<InvalidNoreturn>;
def err_noreturn_block_has_return_expr : Error<
"block declared 'noreturn' should not return">;
def err_noreturn_missing_on_first_decl : Error<
Index: lib/Sema/SemaDecl.cpp
===================================================================
--- lib/Sema/SemaDecl.cpp (revision 198292)
+++ lib/Sema/SemaDecl.cpp (working copy)
@@ -7392,6 +7392,9 @@
AddToScope = false;
}
+ if (NewFD->isNoReturn() && !NewFD->getResultType()->isVoidType())
+ Diag(NewFD->getLocation(), diag::warn_noreturn_function_has_nonvoid_type)
+ << NewFD;
return NewFD;
}
Index: test/Sema/warn-noreturn-return-type.c
===================================================================
--- test/Sema/warn-noreturn-return-type.c (revision 0)
+++ test/Sema/warn-noreturn-return-type.c (working copy)
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -Winvalid-noreturn
+__attribute__((noreturn)) void test1();
+
+__attribute__((noreturn)) int test2(); // expected-warning{{function
'test2' declared 'noreturn' should not have a non-void return type}}
+
+__attribute__((noreturn)) float test3(); //
expected-warning{{function 'test3' declared 'noreturn' should not have
a non-void return type}}
+
+_Noreturn void test4();
+
+_Noreturn int test5(); // expected-warning{{function 'test5' declared
'noreturn' should not have a non-void return type}}
+
+_Noreturn float test6(); // expected-warning{{function 'test6'
declared 'noreturn' should not have a non-void return type}}
Index: test/SemaCXX/warn-noreturn-return-type.cpp
===================================================================
--- test/SemaCXX/warn-noreturn-return-type.cpp (revision 0)
+++ test/SemaCXX/warn-noreturn-return-type.cpp (working copy)
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -Winvalid-noreturn -std=c++11
+void test1 [[noreturn]]();
+
+int test2 [[noreturn]](); // expected-warning{{function 'test2'
declared 'noreturn' should not have a non-void return type}}
+
+float test3 [[noreturn]](); // expected-warning{{function 'test3'
declared 'noreturn' should not have a non-void return type}}
More information about the cfe-commits
mailing list