summaryrefslogtreecommitdiffstats
path: root/gl/verify.h
diff options
context:
space:
mode:
Diffstat (limited to 'gl/verify.h')
-rw-r--r--gl/verify.h65
1 files changed, 45 insertions, 20 deletions
diff --git a/gl/verify.h b/gl/verify.h
index b63cb26..08268c2 100644
--- a/gl/verify.h
+++ b/gl/verify.h
@@ -1,6 +1,6 @@
1/* Compile-time assert-like macros. 1/* Compile-time assert-like macros.
2 2
3 Copyright (C) 2005-2006, 2009-2023 Free Software Foundation, Inc. 3 Copyright (C) 2005-2006, 2009-2024 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
@@ -188,9 +188,9 @@ template <int w>
188 _gl_verify_type<(R) ? 1 : -1> 188 _gl_verify_type<(R) ? 1 : -1>
189#elif defined _GL_HAVE__STATIC_ASSERT 189#elif defined _GL_HAVE__STATIC_ASSERT
190# define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \ 190# define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \
191 struct { \ 191 struct { \
192 _Static_assert (R, DIAGNOSTIC); \ 192 _Static_assert (R, DIAGNOSTIC); \
193 int _gl_dummy; \ 193 int _gl_dummy; \
194 } 194 }
195#else 195#else
196# define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \ 196# define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \
@@ -212,8 +212,8 @@ template <int w>
212#elif defined _GL_HAVE__STATIC_ASSERT 212#elif defined _GL_HAVE__STATIC_ASSERT
213# define _GL_VERIFY(R, DIAGNOSTIC, ...) _Static_assert (R, DIAGNOSTIC) 213# define _GL_VERIFY(R, DIAGNOSTIC, ...) _Static_assert (R, DIAGNOSTIC)
214#else 214#else
215# define _GL_VERIFY(R, DIAGNOSTIC, ...) \ 215# define _GL_VERIFY(R, DIAGNOSTIC, ...) \
216 extern int (*_GL_GENSYM (_gl_verify_function) (void)) \ 216 extern int (*_GL_GENSYM (_gl_verify_function) (void)) \
217 [_GL_VERIFY_TRUE (R, DIAGNOSTIC)] 217 [_GL_VERIFY_TRUE (R, DIAGNOSTIC)]
218# if 4 < __GNUC__ + (6 <= __GNUC_MINOR__) 218# if 4 < __GNUC__ + (6 <= __GNUC_MINOR__)
219# pragma GCC diagnostic ignored "-Wnested-externs" 219# pragma GCC diagnostic ignored "-Wnested-externs"
@@ -222,22 +222,43 @@ template <int w>
222 222
223/* _GL_STATIC_ASSERT_H is defined if this code is copied into assert.h. */ 223/* _GL_STATIC_ASSERT_H is defined if this code is copied into assert.h. */
224#ifdef _GL_STATIC_ASSERT_H 224#ifdef _GL_STATIC_ASSERT_H
225# if !defined _GL_HAVE__STATIC_ASSERT1 && !defined _Static_assert 225/* Define _Static_assert if needed. */
226/* With clang ≥ 3.8.0 in C++ mode, _Static_assert already works and accepts
227 1 or 2 arguments. We better don't override it, because clang's standard
228 C++ library uses static_assert inside classes in several places, and our
229 replacement via _GL_VERIFY does not work in these contexts. */
230# if (defined __cplusplus && defined __clang__ \
231 && (4 <= __clang_major__ + (8 <= __clang_minor__)))
232# if 5 <= __clang_major__
233/* Avoid "warning: 'static_assert' with no message is a C++17 extension". */
234# pragma clang diagnostic ignored "-Wc++17-extensions"
235# else
236/* Avoid "warning: static_assert with no message is a C++1z extension". */
237# pragma clang diagnostic ignored "-Wc++1z-extensions"
238# endif
239# elif !defined _GL_HAVE__STATIC_ASSERT1 && !defined _Static_assert
226# if !defined _MSC_VER || defined __clang__ 240# if !defined _MSC_VER || defined __clang__
227# define _Static_assert(...) \ 241# define _Static_assert(...) \
228 _GL_VERIFY (__VA_ARGS__, "static assertion failed", -) 242 _GL_VERIFY (__VA_ARGS__, "static assertion failed", -)
229# else 243# else
230 /* Work around MSVC preprocessor incompatibility with ISO C; see 244# if defined __cplusplus && _MSC_VER >= 1910
231 <https://stackoverflow.com/questions/5134523/>. */ 245 /* In MSVC 14.1 or newer, static_assert accepts one or two arguments,
232# define _Static_assert(R, ...) \ 246 but _Static_assert is not defined. */
233 _GL_VERIFY ((R), "static assertion failed", -) 247# define _Static_assert static_assert
248# else
249 /* Work around MSVC preprocessor incompatibility with ISO C; see
250 <https://stackoverflow.com/questions/5134523/>. */
251# define _Static_assert(R, ...) \
252 _GL_VERIFY ((R), "static assertion failed", -)
253# endif
234# endif 254# endif
235# endif 255# endif
256/* Define static_assert if needed. */
236# if (!defined static_assert \ 257# if (!defined static_assert \
237 && __STDC_VERSION__ < 202311 \ 258 && __STDC_VERSION__ < 202311 \
238 && (!defined __cplusplus \ 259 && (!defined __cplusplus \
239 || (__cpp_static_assert < 201411 \ 260 || (__cpp_static_assert < 201411 \
240 && __GNUG__ < 6 && __clang_major__ < 6))) 261 && __GNUG__ < 6 && __clang_major__ < 6 && _MSC_VER < 1910)))
241# if defined __cplusplus && _MSC_VER >= 1900 && !defined __clang__ 262# if defined __cplusplus && _MSC_VER >= 1900 && !defined __clang__
242/* MSVC 14 in C++ mode supports the two-arguments static_assert but not 263/* MSVC 14 in C++ mode supports the two-arguments static_assert but not
243 the one-argument static_assert, and it does not support _Static_assert. 264 the one-argument static_assert, and it does not support _Static_assert.
@@ -250,6 +271,8 @@ template <int w>
250# define _GL_SA3 static_assert 271# define _GL_SA3 static_assert
251# define _GL_SA_PICK(x1,x2,x3,x4,...) x4 272# define _GL_SA_PICK(x1,x2,x3,x4,...) x4
252# define static_assert(...) _GL_EXPAND(_GL_SA_PICK(__VA_ARGS__,_GL_SA3,_GL_SA2,_GL_SA1)) (__VA_ARGS__) 273# define static_assert(...) _GL_EXPAND(_GL_SA_PICK(__VA_ARGS__,_GL_SA3,_GL_SA2,_GL_SA1)) (__VA_ARGS__)
274/* Avoid "fatal error C1189: #error: The C++ Standard Library forbids macroizing keywords." */
275# define _ALLOW_KEYWORD_MACROS 1
253# else 276# else
254# define static_assert _Static_assert /* C11 requires this #define. */ 277# define static_assert _Static_assert /* C11 requires this #define. */
255# endif 278# endif
@@ -268,14 +291,16 @@ template <int w>
268# define _GL_HAS_BUILTIN_TRAP 0 291# define _GL_HAS_BUILTIN_TRAP 0
269#endif 292#endif
270 293
271#if defined __clang_major__ && __clang_major__ < 5 294#ifndef _GL_HAS_BUILTIN_UNREACHABLE
272# define _GL_HAS_BUILTIN_UNREACHABLE 0 295# if defined __clang_major__ && __clang_major__ < 5
273#elif 4 < __GNUC__ + (5 <= __GNUC_MINOR__) 296# define _GL_HAS_BUILTIN_UNREACHABLE 0
274# define _GL_HAS_BUILTIN_UNREACHABLE 1 297# elif 4 < __GNUC__ + (5 <= __GNUC_MINOR__)
275#elif defined __has_builtin 298# define _GL_HAS_BUILTIN_UNREACHABLE 1
276# define _GL_HAS_BUILTIN_UNREACHABLE __has_builtin (__builtin_unreachable) 299# elif defined __has_builtin
277#else 300# define _GL_HAS_BUILTIN_UNREACHABLE __has_builtin (__builtin_unreachable)
278# define _GL_HAS_BUILTIN_UNREACHABLE 0 301# else
302# define _GL_HAS_BUILTIN_UNREACHABLE 0
303# endif
279#endif 304#endif
280 305
281/* Each of these macros verifies that its argument R is nonzero. To 306/* Each of these macros verifies that its argument R is nonzero. To