summaryrefslogtreecommitdiffstats
path: root/gl/stddef.in.h
diff options
context:
space:
mode:
Diffstat (limited to 'gl/stddef.in.h')
-rw-r--r--gl/stddef.in.h131
1 files changed, 116 insertions, 15 deletions
diff --git a/gl/stddef.in.h b/gl/stddef.in.h
index 6eadcc3d..e8c55ff1 100644
--- a/gl/stddef.in.h
+++ b/gl/stddef.in.h
@@ -1,6 +1,6 @@
1/* A substitute for POSIX 2008 <stddef.h>, for platforms that have issues. 1/* A substitute for POSIX 2008 <stddef.h>, for platforms that have issues.
2 2
3 Copyright (C) 2009-2023 Free Software Foundation, Inc. 3 Copyright (C) 2009-2025 Free Software Foundation, Inc.
4 4
5 This file is free software: you can redistribute it and/or modify 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 6 it under the terms of the GNU Lesser General Public License as
@@ -18,7 +18,7 @@
18/* Written by Eric Blake. */ 18/* Written by Eric Blake. */
19 19
20/* 20/*
21 * POSIX 2008 <stddef.h> for platforms that have issues. 21 * POSIX 2008 and ISO C 23 <stddef.h> for platforms that have issues.
22 * <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/stddef.h.html> 22 * <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/stddef.h.html>
23 */ 23 */
24 24
@@ -27,19 +27,27 @@
27#endif 27#endif
28@PRAGMA_COLUMNS@ 28@PRAGMA_COLUMNS@
29 29
30#if defined __need_wchar_t || defined __need_size_t \ 30#if (defined __need_wchar_t || defined __need_size_t \
31 || defined __need_ptrdiff_t || defined __need_NULL \ 31 || defined __need_ptrdiff_t || defined __need_NULL \
32 || defined __need_wint_t 32 || defined __need_wint_t) \
33 /* Avoid warning triggered by "gcc -std=gnu23 -Wsystem-headers" \
34 in GCC 13.3 and 14.2 \
35 <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114870>. */ \
36 && !@STDDEF_NOT_IDEMPOTENT@
33/* Special invocation convention inside gcc header files. In 37/* Special invocation convention inside gcc header files. In
34 particular, gcc provides a version of <stddef.h> that blindly 38 particular, <stddef.h> in some ancient versions of GCC blindly
35 redefines NULL even when __need_wint_t was defined, even though 39 redefined NULL when __need_wint_t was defined, even though wint_t
36 wint_t is not normally provided by <stddef.h>. Hence, we must 40 is not normally provided by <stddef.h>.
41 (FIXME: It's not clear what GCC versions those were - perhaps so
42 ancient that we can stop worrying about this?)
43 Although glibc 2.26 (2017) and later do not use __need_wint_t,
44 for portability to macOS, Cygwin, Haiku, and older Glibc + GCC,
37 remember if special invocation has ever been used to obtain wint_t, 45 remember if special invocation has ever been used to obtain wint_t,
38 in which case we need to clean up NULL yet again. */ 46 in which case we need to clean up NULL yet again. */
39 47
40# if !(defined _@GUARD_PREFIX@_STDDEF_H && defined _GL_STDDEF_WINT_T) 48# if !(defined _@GUARD_PREFIX@_STDDEF_H && defined _@GUARD_PREFIX@_STDDEF_WINT_T)
41# ifdef __need_wint_t 49# ifdef __need_wint_t
42# define _GL_STDDEF_WINT_T 50# define _@GUARD_PREFIX@_STDDEF_WINT_T
43# endif 51# endif
44# @INCLUDE_NEXT@ @NEXT_STDDEF_H@ 52# @INCLUDE_NEXT@ @NEXT_STDDEF_H@
45 /* On TinyCC, make sure that the macros that indicate the special invocation 53 /* On TinyCC, make sure that the macros that indicate the special invocation
@@ -52,13 +60,20 @@
52# endif 60# endif
53 61
54#else 62#else
63/* For @STDDEF_NOT_IDEMPOTENT@. */
64# undef __need_wchar_t
65# undef __need_size_t
66# undef __need_ptrdiff_t
67# undef __need_NULL
68# undef __need_wint_t
69
55/* Normal invocation convention. */ 70/* Normal invocation convention. */
56 71
57# ifndef _@GUARD_PREFIX@_STDDEF_H 72# ifndef _@GUARD_PREFIX@_STDDEF_H
58 73
59/* On AIX 7.2, with xlc in 64-bit mode, <stddef.h> defines max_align_t to a 74/* On AIX 7.2, with xlc in 64-bit mode, <stddef.h> defines max_align_t to a
60 type with alignment 4, but 'long' has alignment 8. */ 75 type with alignment 4, but 'long' has alignment 8. */
61# if defined _AIX && defined __LP64__ 76# if defined _AIX && defined __LP64__ && !@HAVE_MAX_ALIGN_T@
62# if !GNULIB_defined_max_align_t 77# if !GNULIB_defined_max_align_t
63# ifdef _MAX_ALIGN_T 78# ifdef _MAX_ALIGN_T
64/* /usr/include/stddef.h has already defined max_align_t. Override it. */ 79/* /usr/include/stddef.h has already defined max_align_t. Override it. */
@@ -69,17 +84,24 @@ typedef long rpl_max_align_t;
69typedef long max_align_t; 84typedef long max_align_t;
70# define _MAX_ALIGN_T 85# define _MAX_ALIGN_T
71# endif 86# endif
87# define __CLANG_MAX_ALIGN_T_DEFINED
72# define GNULIB_defined_max_align_t 1 88# define GNULIB_defined_max_align_t 1
73# endif 89# endif
74# endif 90# endif
75 91
92# if !defined _GCC_NULLPTR_T && !@NULLPTR_T_NEEDS_STDDEF@
93 /* Suppress unwanted nullptr_t typedef. See
94 <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114869>. */
95# define _GCC_NULLPTR_T
96# endif
97
76/* The include_next requires a split double-inclusion guard. */ 98/* The include_next requires a split double-inclusion guard. */
77 99
78# @INCLUDE_NEXT@ @NEXT_STDDEF_H@ 100# @INCLUDE_NEXT@ @NEXT_STDDEF_H@
79 101
80/* On NetBSD 5.0, the definition of NULL lacks proper parentheses. */ 102/* On NetBSD 5.0, the definition of NULL lacks proper parentheses. */
81# if (@REPLACE_NULL@ \ 103# if (@REPLACE_NULL@ \
82 && (!defined _@GUARD_PREFIX@_STDDEF_H || defined _GL_STDDEF_WINT_T)) 104 && (!defined _@GUARD_PREFIX@_STDDEF_H || defined _@GUARD_PREFIX@_STDDEF_WINT_T))
83# undef NULL 105# undef NULL
84# ifdef __cplusplus 106# ifdef __cplusplus
85 /* ISO C++ says that the macro NULL must expand to an integer constant 107 /* ISO C++ says that the macro NULL must expand to an integer constant
@@ -100,9 +122,31 @@ typedef long max_align_t;
100# ifndef _@GUARD_PREFIX@_STDDEF_H 122# ifndef _@GUARD_PREFIX@_STDDEF_H
101# define _@GUARD_PREFIX@_STDDEF_H 123# define _@GUARD_PREFIX@_STDDEF_H
102 124
103/* Some platforms lack wchar_t. */ 125/* This file uses _Noreturn, _GL_ATTRIBUTE_NOTHROW. */
104#if !@HAVE_WCHAR_T@ 126#if !_GL_CONFIG_H_INCLUDED
105# define wchar_t int 127 #error "Please include config.h first."
128#endif
129
130/* _GL_ATTRIBUTE_NOTHROW declares that the function does not throw exceptions.
131 */
132#ifndef _GL_ATTRIBUTE_NOTHROW
133# if defined __cplusplus
134# if (__GNUC__ + (__GNUC_MINOR__ >= 8) > 2) || __clang_major__ >= 4
135# if __cplusplus >= 201103L
136# define _GL_ATTRIBUTE_NOTHROW noexcept (true)
137# else
138# define _GL_ATTRIBUTE_NOTHROW throw ()
139# endif
140# else
141# define _GL_ATTRIBUTE_NOTHROW
142# endif
143# else
144# if (__GNUC__ + (__GNUC_MINOR__ >= 3) > 3) || defined __clang__
145# define _GL_ATTRIBUTE_NOTHROW __attribute__ ((__nothrow__))
146# else
147# define _GL_ATTRIBUTE_NOTHROW
148# endif
149# endif
106#endif 150#endif
107 151
108/* Some platforms lack max_align_t. The check for _GCC_MAX_ALIGN_T is 152/* Some platforms lack max_align_t. The check for _GCC_MAX_ALIGN_T is
@@ -137,11 +181,68 @@ typedef union
137 long int __i _GL_STDDEF_ALIGNAS (long int); 181 long int __i _GL_STDDEF_ALIGNAS (long int);
138} rpl_max_align_t; 182} rpl_max_align_t;
139# define max_align_t rpl_max_align_t 183# define max_align_t rpl_max_align_t
184# define __CLANG_MAX_ALIGN_T_DEFINED
140# define GNULIB_defined_max_align_t 1 185# define GNULIB_defined_max_align_t 1
141# endif 186# endif
142# endif 187# endif
143#endif 188#endif
144 189
190/* ISO C 23 ยง 7.21.1 The unreachable macro */
191/* This macro is only usable in C, not in C++.
192 There is no way to define it as a macro in C++, because that would break code
193 that does
194 #include <utility>
195 ... std::unreachable() ...
196 Similarly, there is no way to define it as an inline function in C++, because
197 that would break code that does
198 #include <utility>
199 using std::unreachable;
200 As a workaround, we define a macro gl_unreachable, that is like unreachable,
201 but is usable in both C and C++. */
202
203/* Code borrowed from verify.h. */
204#ifndef _GL_HAS_BUILTIN_UNREACHABLE
205# if defined __clang_major__ && __clang_major__ < 5
206# define _GL_HAS_BUILTIN_UNREACHABLE 0
207# elif 4 < __GNUC__ + (5 <= __GNUC_MINOR__) && !defined __clang__
208# define _GL_HAS_BUILTIN_UNREACHABLE 1
209# elif defined __has_builtin
210# define _GL_HAS_BUILTIN_UNREACHABLE __has_builtin (__builtin_unreachable)
211# else
212# define _GL_HAS_BUILTIN_UNREACHABLE 0
213# endif
214#endif
215
216#if _GL_HAS_BUILTIN_UNREACHABLE
217# define gl_unreachable() __builtin_unreachable ()
218#elif 1200 <= _MSC_VER
219# define gl_unreachable() __assume (0)
220#elif !defined __cplusplus && @HAVE_C_UNREACHABLE@
221# define gl_unreachable() unreachable ()
222#else
223/* Declare abort(), without including <stdlib.h>. */
224extern
225# if defined __cplusplus
226"C"
227# endif
228_Noreturn
229void abort (void)
230# if defined __cplusplus && (__GLIBC__ >= 2)
231_GL_ATTRIBUTE_NOTHROW
232# endif
233;
234# define gl_unreachable() abort ()
235#endif
236
237#if !defined __cplusplus && !@HAVE_C_UNREACHABLE@
238/* In C, define unreachable as a macro. */
239
240# ifndef unreachable
241# define unreachable() gl_unreachable ()
242# endif
243
244#endif
245
145# endif /* _@GUARD_PREFIX@_STDDEF_H */ 246# endif /* _@GUARD_PREFIX@_STDDEF_H */
146# endif /* _@GUARD_PREFIX@_STDDEF_H */ 247# endif /* _@GUARD_PREFIX@_STDDEF_H */
147#endif /* __need_XXX */ 248#endif /* __need_XXX */