| 1 |
/* A substitute for ISO C11 <stdnoreturn.h>. |
| 2 |
|
| 3 |
Copyright 2012-2025 Free Software Foundation, Inc. |
| 4 |
|
| 5 |
This file is free software: you can redistribute it and/or modify |
| 6 |
it under the terms of the GNU Lesser General Public License as |
| 7 |
published by the Free Software Foundation; either version 2.1 of the |
| 8 |
License, or (at your option) any later version. |
| 9 |
|
| 10 |
This file is distributed in the hope that it will be useful, |
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
GNU Lesser General Public License for more details. |
| 14 |
|
| 15 |
You should have received a copy of the GNU Lesser General Public License |
| 16 |
along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
| 17 |
|
| 18 |
/* Written by Paul Eggert. */ |
| 19 |
|
| 20 |
/* This file uses _Noreturn. */ |
| 21 |
#if !_GL_CONFIG_H_INCLUDED |
| 22 |
#error "Please include config.h first." |
| 23 |
#endif |
| 24 |
|
| 25 |
#ifndef noreturn |
| 26 |
|
| 27 |
/* ISO C11 <stdnoreturn.h> for platforms that lack it. |
| 28 |
|
| 29 |
References: |
| 30 |
ISO C11 (latest free draft |
| 31 |
<https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf>) |
| 32 |
section 7.23 |
| 33 |
|
| 34 |
<stdnoreturn.h> is obsolescent in C23, so new code should avoid it. */ |
| 35 |
|
| 36 |
/* The definition of _Noreturn is copied here. */ |
| 37 |
|
| 38 |
#if 1200 <= _MSC_VER || defined __CYGWIN__ |
| 39 |
/* On MSVC, standard include files contain declarations like |
| 40 |
__declspec (noreturn) void abort (void); |
| 41 |
"#define noreturn _Noreturn" would cause this declaration to be rewritten |
| 42 |
to the invalid |
| 43 |
__declspec (__declspec (noreturn)) void abort (void); |
| 44 |
|
| 45 |
Similarly, on Cygwin, standard include files contain declarations like |
| 46 |
void __cdecl abort (void) __attribute__ ((noreturn)); |
| 47 |
"#define noreturn _Noreturn" would cause this declaration to be rewritten |
| 48 |
to the invalid |
| 49 |
void __cdecl abort (void) __attribute__ ((__attribute__ ((__noreturn__)))); |
| 50 |
|
| 51 |
Instead, define noreturn to empty, so that such declarations are rewritten to |
| 52 |
__declspec () void abort (void); |
| 53 |
or |
| 54 |
void __cdecl abort (void) __attribute__ (()); |
| 55 |
respectively. This gives up on noreturn's advice to the compiler but at |
| 56 |
least it is valid code. */ |
| 57 |
# define noreturn /*empty*/ |
| 58 |
#else |
| 59 |
# define noreturn _Noreturn |
| 60 |
#endif |
| 61 |
|
| 62 |
/* Did he ever return? |
| 63 |
No he never returned |
| 64 |
And his fate is still unlearn'd ... |
| 65 |
-- Steiner J, Hawes BL. M.T.A. (1949) */ |
| 66 |
|
| 67 |
#endif /* noreturn */ |