[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: clang and _Noreturn
From: |
Bruno Haible |
Subject: |
Re: clang and _Noreturn |
Date: |
Sun, 23 Apr 2017 22:58:57 +0200 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-72-generic; KDE/5.18.0; x86_64; ; ) |
Hi Paul,
> Although this will work for GCC and Clang, I suppose it might cause other
> compilers to generate slightly-less-efficient code, because they won't know
> that
> print_and_abort does not return.
Good point. Yes.
> To avoid that problem, how about this further patch?
Yes, this fits my bill too. Thanks!
Once this is in, how about generalizing it? For other uses than in the module
'obstack', I would like to have a module that one can use without #ifdef,
without surprises, and that produces best efficient code for all compilers.
It should define two macros:
1) a macro for use with function declarations and definitions only,
2) a macro for use with function pointers (variables, struct elements etc.).
1) would be the __attribute_noreturn__ that we have in obstack.h.
2) would be the 'Noreturn' that you define in obstack.c.
And a consistent naming. _GL_NORETURN_FUNC and _GL_NORETURN_FUNCPTR maybe?
Ideally, one should be able to define the same thing, in the same header file,
for C++ as well. If the compiler supports C++11 or newer, one can use
'[[noreturn]]' instead of '_Noreturn'; otherwise use an empty definition
instead of '_Noreturn'.
There is one complication, though: In C++, you cannot write
extern [[noreturn]] void foo (void);
You have to write
[[noreturn]] extern void foo (void);
or
extern void foo [[noreturn]] (void);
On the other hand, in C, the valid positions of the _Noreturn keyword are
_Noreturn extern void foo (void);
extern _Noreturn void foo (void);
extern void _Noreturn foo (void);
So, the only position that works for both C and C++ is the first one:
_GL_NORETURN_FUNC extern void foo (void);
Bruno
- clang and _Noreturn, Bruno Haible, 2017/04/22
- Re: clang and _Noreturn, Paul Eggert, 2017/04/22
- Re: clang and _Noreturn, Bruno Haible, 2017/04/23
- Re: clang and _Noreturn, Paul Eggert, 2017/04/23
- Re: clang and _Noreturn,
Bruno Haible <=
- Re: clang and _Noreturn, Paul Eggert, 2017/04/23
- Re: clang and _Noreturn, Bruno Haible, 2017/04/24
- Re: clang and _Noreturn, Paul Eggert, 2017/04/24
- Re: clang and _Noreturn, Bruno Haible, 2017/04/25
- Re: clang and _Noreturn, Paul Eggert, 2017/04/25
- Re: clang and _Noreturn, Bruno Haible, 2017/04/26
- Re: clang and _Noreturn, Bruno Haible, 2017/04/26