[PATCH] NoReturn Warning: Non-Void Return Type
dblaikie at gmail.com
dblaikie at gmail.com
Sun Jan 5 16:30:12 PST 2014
Is this an existing warning in another compiler? Is it finding bugs? How
does this interact with virtual functions? (what if I'm overriding a
non-void non-noreturn function with a noreturn function?)
On Sun Jan 05 2014 at 2:18:43 PM, Michael Bao <mike.h.bao at gmail.com> wrote:
> Rebased off Revision 198572.
>
> - Reword diagnostic to avoid double negative
> - Pass in -std=c11 to the C test.
> - Put [[noreturn]] attribute in front of function decl in C++ tests.
>
> http://llvm-reviews.chandlerc.com/D2507
>
> CHANGE SINCE LAST DIFF
> http://llvm-reviews.chandlerc.com/D2507?vs=6345&id=6353#toc
>
> Files:
> include/clang/Basic/DiagnosticSemaKinds.td
> lib/Sema/SemaDecl.cpp
> test/Sema/warn-noreturn-return-type.c
> test/SemaCXX/warn-noreturn-return-type.cpp
>
> Index: include/clang/Basic/DiagnosticSemaKinds.td
> ===================================================================
> --- include/clang/Basic/DiagnosticSemaKinds.td
> +++ include/clang/Basic/DiagnosticSemaKinds.td
> @@ -6459,6 +6459,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 have a '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
> +++ lib/Sema/SemaDecl.cpp
> @@ -7391,6 +7391,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
> +++ test/Sema/warn-noreturn-return-type.c
> @@ -0,0 +1,12 @@
> +// RUN: %clang_cc1 %s -fsyntax-only -verify -Winvalid-noreturn -std=c11
> +__attribute__((noreturn)) void test1();
> +
> +__attribute__((noreturn)) int test2(); // expected-warning{{function
> 'test2' declared 'noreturn' should have a 'void' return type}}
> +
> +__attribute__((noreturn)) float test3(); // expected-warning{{function
> 'test3' declared 'noreturn' should have a 'void' return type}}
> +
> +_Noreturn void test4();
> +
> +_Noreturn int test5(); // expected-warning{{function 'test5' declared
> 'noreturn' should have a 'void' return type}}
> +
> +_Noreturn float test6(); // expected-warning{{function 'test6' declared
> 'noreturn' should have a 'void' return type}}
> Index: test/SemaCXX/warn-noreturn-return-type.cpp
> ===================================================================
> --- test/SemaCXX/warn-noreturn-return-type.cpp
> +++ test/SemaCXX/warn-noreturn-return-type.cpp
> @@ -0,0 +1,6 @@
> +// RUN: %clang_cc1 %s -fsyntax-only -verify -Winvalid-noreturn -std=c++11
> +[[noreturn]] void test1();
> +
> +[[noreturn]] int test2(); // expected-warning{{function 'test2' declared
> 'noreturn' should have a 'void' return type}}
> +
> +[[noreturn]] float test3(); // expected-warning{{function 'test3'
> declared 'noreturn' should have a 'void' return type}}
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140106/41954736/attachment.html>
More information about the cfe-commits
mailing list