[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] test-raise: use _Noreturn
From: |
Bruno Haible |
Subject: |
Re: [PATCH] test-raise: use _Noreturn |
Date: |
Fri, 7 Oct 2011 11:38:37 +0200 |
User-agent: |
KMail/1.13.6 (Linux/2.6.37.6-0.5-desktop; KDE/4.6.0; x86_64; ; ) |
Paolo Bonzini wrote:
> exit is declared as a nonreturning built-in by GCC
> (devel/gcc/gcc/builtins.def):
Indeed, the fact that it's a built-in makes a difference:
========================== foo.c ================================
extern /*__attribute__ ((__noreturn__))*/ void exit (int);
static __attribute__ ((__noreturn__)) void handler (int sig)
{
exit (0);
}
=================================================================
$ gcc -Wall -Wmissing-noreturn -c foo.c
$ gcc -Wall -Wmissing-noreturn -c foo.c -Dexit=otherfunc
foo.c: In function 'handler':
foo.c:5:1: warning: 'noreturn' function does return
This also answers Eric's question whether we should do something
in gnulib's <stdlib.h> replacement.
I'm applying Bernhard's patch, with comments.
> For non-GCC compilers I don't think we care about warnings, do we?
Right.
Bruno
2011-10-07 Bernhard Voelker <address@hidden>
raise tests: Avoid a GCC warning.
* tests/test-raise.c (handler): Use _Noreturn.
--- a/tests/test-raise.c
+++ b/tests/test-raise.c
@@ -25,7 +25,10 @@ SIGNATURE_CHECK (raise, int, (int));
#include "macros.h"
-static void
+/* It is safe to use _Noreturn here: exit() never returns, and GCC knows that
+ exit() is a non-returning function, even on platforms where its declaration
+ in <stdlib.h> does not have the 'noreturn' attribute. */
+static _Noreturn void
handler (int sig)
{
exit (0);
--
In memoriam Anna Politkovskaya <http://en.wikipedia.org/wiki/Anna_Politkovskaya>
- [PATCH] test-raise: use _Noreturn, Bernhard Voelker, 2011/10/05
- Re: [PATCH] test-raise: use _Noreturn, Bruno Haible, 2011/10/05
- Re: [PATCH] test-raise: use _Noreturn, Eric Blake, 2011/10/05
- Re: [PATCH] test-raise: use _Noreturn, Eric Blake, 2011/10/05
- Re: [PATCH] test-raise: use _Noreturn, Bruno Haible, 2011/10/05
- Re: [PATCH] test-raise: use _Noreturn, Bernhard Voelker, 2011/10/06
- Re: [PATCH] test-raise: use _Noreturn, Bruno Haible, 2011/10/06
- Re: [PATCH] test-raise: use _Noreturn, Bernhard Voelker, 2011/10/06
- Re: [PATCH] test-raise: use _Noreturn, Paolo Bonzini, 2011/10/07
- Re: [PATCH] test-raise: use _Noreturn,
Bruno Haible <=