[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AC_C_NORETURN macro?

From: Eric Blake
Subject: Re: AC_C_NORETURN macro?
Date: Thu, 26 Apr 2012 08:14:51 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:11.0) Gecko/20120329 Thunderbird/11.0.1

On 04/26/2012 02:54 AM, Vincent Lefevre wrote:
> The gnulib code, as I can see it under Debian, looks strange.
> In lib/
> #if 1200 <= _MSC_VER
> /* Standard include files on this platform contain declarations like
>    "__declspec (noreturn) void abort (void);".  "#define noreturn
>    _Noreturn" would cause this declaration to be rewritten to the
>    invalid "__declspec (__declspec (noreturn)) void abort (void);".
>    Instead, define noreturn to empty, so that such declarations are
>    rewritten to "__declspec () void abort (void);", which is
>    equivalent to "void abort (void);"; this gives up on noreturn's
>    advice to the compiler but at least it is valid code.  */
> # define noreturn /*empty*/
> #else
> # define noreturn _Noreturn
> #endif
> IMHO, the problem with _MSC_VER (which is not a bug, because
> "noreturn" wasn't reserved) means that using the <stdnoreturn.h>
> header is not the right solution for code that needs to be pre-C11
> compatible;

If I write C11 code:

#include <stdnoreturn.h>
#include <stdio.h>

then I expect things to work.  But _MSC_VER system headers use noreturn
in a non-C11 manner, such that the only way for this to work via gnulib
is to make 'noreturn' a no-op on that platform, until such time as
Microsoft updates their headers.  Microsoft has a history of namespace
pollution; had their compiler used '__declspec (__noreturn)' instead of
'__declspec (noreturn)', we would not be facing this clash.  The whole
point of gnulib is to give me enough support so that I can write code
that is valid C11, and also which compiles under non-C11 compilers,
without any extra #ifdef work in my code (since gnulib took care of it
for me).

> indeed some implementations may have another use of
> "noreturn".

Not if they were compliant to C99 (since C99 didn't reserve 'noreturn',
then system headers under C99 mode should not be using that symbol).

> but I don't see how it can be correct on a non-GCC non-SunPro C11
> implementation: _Noreturn would get defined to nothing; the code
> would be valid, but the C11 _Noreturn function specifier would not
> be used.

Correct.  _Noreturn is an optimization hint; your code will still
function correctly if the specifier is not present.  The gnulib choice
to define it away on problematic systems is intentional.

Eric Blake   address@hidden    +1-919-301-3266
Libvirt virtualization library

Attachment: signature.asc
Description: OpenPGP digital signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]