bug-gnulib
[Top][All Lists]
Advanced

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

Re: clang and _Noreturn


From: Paul Eggert
Subject: Re: clang and _Noreturn
Date: Sat, 22 Apr 2017 14:06:07 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0

Bruno Haible wrote:
What is the semantic difference between _Noreturn and
__attribute_noreturn__?

__attribute__ ((__noreturn__)), which the latter expands to, also works with function pointers, whereas _Noreturn does not. The distinction can matter when a function's address is assigned to a function pointer. Clang checks for __attribute__ ((__noreturn__)) compatibility when assigning function pointers; GCC does not, which can lead to weird results. For example:

_Noreturn void nr (void) { for (;;); }
__attribute__ ((__noreturn__)) void anr (void) { for (;;); }

/* Valid.  */
void (*a) (void) = nr;
void (*b) (void) = anr;
__attribute__ ((__noreturn__)) void (*c) (void) = anr;

/* Invalid, as _Noreturn applies only to function definitions.  */
_Noreturn void (*d) (void) = nr;
_Noreturn void (*e) (void) = anr;

/* Allowed by GCC, but weirdly disallowed by clang because f is not declared 
with
   __attribute__ ((__noreturn__)).  */
__attribute__ ((__noreturn__)) void (*f) (void) = nr;

GCC does a better job in this area, and it's not clear that it's worth catering to clang's idiosyncracies here.



reply via email to

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