diff options
| author | Paul Eggert | 2019-08-14 18:13:27 -0700 |
|---|---|---|
| committer | Paul Eggert | 2019-08-14 18:13:54 -0700 |
| commit | aa1411b20fba73ca6fde90fc9ce62cc8a854bf20 (patch) | |
| tree | d390dc726f47658c684d3b2cc1e1b6137b198c16 /lib/verify.h | |
| parent | 370f07046b13035948655d450ed1b58d20a0cdd4 (diff) | |
| download | emacs-aa1411b20fba73ca6fde90fc9ce62cc8a854bf20.tar.gz emacs-aa1411b20fba73ca6fde90fc9ce62cc8a854bf20.zip | |
Update from Gnulib
This incorporates:
2019-08-14 intprops: pacify picky GCC
2019-08-14 intprops: support unsigned *_WRAPV results
2019-08-12 verify: improve diagnostic quality in recent GCC
* lib/intprops.h, lib/verify.h: Copy from Gnulib.
Diffstat (limited to 'lib/verify.h')
| -rw-r--r-- | lib/verify.h | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/lib/verify.h b/lib/verify.h index 9b8e1ed20fa..afdc1ad81f1 100644 --- a/lib/verify.h +++ b/lib/verify.h | |||
| @@ -175,9 +175,11 @@ | |||
| 175 | #define _GL_GENSYM(prefix) _GL_CONCAT (prefix, _GL_COUNTER) | 175 | #define _GL_GENSYM(prefix) _GL_CONCAT (prefix, _GL_COUNTER) |
| 176 | 176 | ||
| 177 | /* Verify requirement R at compile-time, as an integer constant expression | 177 | /* Verify requirement R at compile-time, as an integer constant expression |
| 178 | that returns 1. If R is false, fail at compile-time. */ | 178 | that returns 1. If R is false, fail at compile-time, preferably |
| 179 | with a diagnostic that includes the string-literal DIAGNOSTIC. */ | ||
| 179 | 180 | ||
| 180 | #define _GL_VERIFY_TRUE(R) (!!sizeof (_GL_VERIFY_TYPE (R))) | 181 | #define _GL_VERIFY_TRUE(R, DIAGNOSTIC) \ |
| 182 | (!!sizeof (_GL_VERIFY_TYPE (R, DIAGNOSTIC))) | ||
| 181 | 183 | ||
| 182 | #ifdef __cplusplus | 184 | #ifdef __cplusplus |
| 183 | # if !GNULIB_defined_struct__gl_verify_type | 185 | # if !GNULIB_defined_struct__gl_verify_type |
| @@ -187,15 +189,16 @@ template <int w> | |||
| 187 | }; | 189 | }; |
| 188 | # define GNULIB_defined_struct__gl_verify_type 1 | 190 | # define GNULIB_defined_struct__gl_verify_type 1 |
| 189 | # endif | 191 | # endif |
| 190 | # define _GL_VERIFY_TYPE(R) _gl_verify_type<(R) ? 1 : -1> | 192 | # define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \ |
| 191 | #elif defined _GL_HAVE__STATIC_ASSERT1 | 193 | _gl_verify_type<(R) ? 1 : -1> |
| 192 | # define _GL_VERIFY_TYPE(R) \ | 194 | #elif defined _GL_HAVE__STATIC_ASSERT |
| 195 | # define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \ | ||
| 193 | struct { \ | 196 | struct { \ |
| 194 | _Static_assert (R); \ | 197 | _Static_assert (R, DIAGNOSTIC); \ |
| 195 | int _gl_dummy; \ | 198 | int _gl_dummy; \ |
| 196 | } | 199 | } |
| 197 | #else | 200 | #else |
| 198 | # define _GL_VERIFY_TYPE(R) \ | 201 | # define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \ |
| 199 | struct { unsigned int _gl_verify_error_if_negative: (R) ? 1 : -1; } | 202 | struct { unsigned int _gl_verify_error_if_negative: (R) ? 1 : -1; } |
| 200 | #endif | 203 | #endif |
| 201 | 204 | ||
| @@ -214,7 +217,7 @@ template <int w> | |||
| 214 | #else | 217 | #else |
| 215 | # define _GL_VERIFY(R, DIAGNOSTIC, ...) \ | 218 | # define _GL_VERIFY(R, DIAGNOSTIC, ...) \ |
| 216 | extern int (*_GL_GENSYM (_gl_verify_function) (void)) \ | 219 | extern int (*_GL_GENSYM (_gl_verify_function) (void)) \ |
| 217 | [_GL_VERIFY_TRUE (R)] | 220 | [_GL_VERIFY_TRUE (R, DIAGNOSTIC)] |
| 218 | #endif | 221 | #endif |
| 219 | 222 | ||
| 220 | /* _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. */ |
| @@ -242,17 +245,19 @@ template <int w> | |||
| 242 | /* Verify requirement R at compile-time. Return the value of the | 245 | /* Verify requirement R at compile-time. Return the value of the |
| 243 | expression E. */ | 246 | expression E. */ |
| 244 | 247 | ||
| 245 | #define verify_expr(R, E) (_GL_VERIFY_TRUE (R) ? (E) : (E)) | 248 | #define verify_expr(R, E) \ |
| 249 | (_GL_VERIFY_TRUE (R, "verify_expr (" #R ", " #E ")") ? (E) : (E)) | ||
| 246 | 250 | ||
| 247 | /* Verify requirement R at compile-time, as a declaration without a | 251 | /* Verify requirement R at compile-time, as a declaration without a |
| 248 | trailing ';'. verify (R) acts like static_assert (R) except that | 252 | trailing ';'. verify (R) acts like static_assert (R) except that |
| 249 | it is portable to C11/C++14 and earlier, and its name is shorter | 253 | it is portable to C11/C++14 and earlier, it can issue better |
| 250 | and may be more convenient. */ | 254 | diagnostics, and its name is shorter and may be more convenient. */ |
| 251 | 255 | ||
| 252 | #ifdef _GL_HAVE__STATIC_ASSERT1 | 256 | #ifdef __PGI |
| 253 | # define verify(R) _Static_assert (R) | 257 | /* PGI barfs if R is long. */ |
| 254 | #else | ||
| 255 | # define verify(R) _GL_VERIFY (R, "verify (...)", -) | 258 | # define verify(R) _GL_VERIFY (R, "verify (...)", -) |
| 259 | #else | ||
| 260 | # define verify(R) _GL_VERIFY (R, "verify (" #R ")", -) | ||
| 256 | #endif | 261 | #endif |
| 257 | 262 | ||
| 258 | #ifndef __has_builtin | 263 | #ifndef __has_builtin |