diff options
| author | Paul Eggert | 2013-07-07 23:15:38 -0700 |
|---|---|---|
| committer | Paul Eggert | 2013-07-07 23:15:38 -0700 |
| commit | 2a74a90a033ec2bf2580ca1c7163209f1cd3faed (patch) | |
| tree | 888b313d913d9ac5da8161784a39c85b4ca5241e /lib/verify.h | |
| parent | 6602769357bba5616c4d36a12d2dce254f4b5fee (diff) | |
| download | emacs-2a74a90a033ec2bf2580ca1c7163209f1cd3faed.tar.gz emacs-2a74a90a033ec2bf2580ca1c7163209f1cd3faed.zip | |
Try to fix FreeBSD 9.1 porting problem.
This incorporates the following merge from gnulib:
2013-07-07 stdalign, verify: port to FreeBSD 9.1, to C11, and to C++11
Fixes: debbugs:14812
Diffstat (limited to 'lib/verify.h')
| -rw-r--r-- | lib/verify.h | 112 |
1 files changed, 60 insertions, 52 deletions
diff --git a/lib/verify.h b/lib/verify.h index 03492efcd3f..d42d0750ee1 100644 --- a/lib/verify.h +++ b/lib/verify.h | |||
| @@ -18,7 +18,7 @@ | |||
| 18 | /* Written by Paul Eggert, Bruno Haible, and Jim Meyering. */ | 18 | /* Written by Paul Eggert, Bruno Haible, and Jim Meyering. */ |
| 19 | 19 | ||
| 20 | #ifndef _GL_VERIFY_H | 20 | #ifndef _GL_VERIFY_H |
| 21 | # define _GL_VERIFY_H | 21 | #define _GL_VERIFY_H |
| 22 | 22 | ||
| 23 | 23 | ||
| 24 | /* Define _GL_HAVE__STATIC_ASSERT to 1 if _Static_assert works as per C11. | 24 | /* Define _GL_HAVE__STATIC_ASSERT to 1 if _Static_assert works as per C11. |
| @@ -31,16 +31,24 @@ | |||
| 31 | Use this only with GCC. If we were willing to slow 'configure' | 31 | Use this only with GCC. If we were willing to slow 'configure' |
| 32 | down we could also use it with other compilers, but since this | 32 | down we could also use it with other compilers, but since this |
| 33 | affects only the quality of diagnostics, why bother? */ | 33 | affects only the quality of diagnostics, why bother? */ |
| 34 | # if (4 < __GNUC__ + (6 <= __GNUC_MINOR__) \ | 34 | #if (4 < __GNUC__ + (6 <= __GNUC_MINOR__) \ |
| 35 | && (201112L <= __STDC_VERSION__ || !defined __STRICT_ANSI__) \ | 35 | && (201112L <= __STDC_VERSION__ || !defined __STRICT_ANSI__) \ |
| 36 | && !defined __cplusplus) | 36 | && !defined __cplusplus) |
| 37 | # define _GL_HAVE__STATIC_ASSERT 1 | 37 | # define _GL_HAVE__STATIC_ASSERT 1 |
| 38 | # endif | 38 | #endif |
| 39 | /* The condition (99 < __GNUC__) is temporary, until we know about the | 39 | /* The condition (99 < __GNUC__) is temporary, until we know about the |
| 40 | first G++ release that supports static_assert. */ | 40 | first G++ release that supports static_assert. */ |
| 41 | # if (99 < __GNUC__) && defined __cplusplus | 41 | #if (99 < __GNUC__) && defined __cplusplus |
| 42 | # define _GL_HAVE_STATIC_ASSERT 1 | 42 | # define _GL_HAVE_STATIC_ASSERT 1 |
| 43 | # endif | 43 | #endif |
| 44 | |||
| 45 | /* FreeBSD 9.1 <sys/cdefs.h>, included by <stddef.h> and lots of other | ||
| 46 | system headers, defines a conflicting _Static_assert that is no | ||
| 47 | better than ours; override it. */ | ||
| 48 | #ifndef _GL_HAVE_STATIC_ASSERT | ||
| 49 | # include <stddef.h> | ||
| 50 | # undef _Static_assert | ||
| 51 | #endif | ||
| 44 | 52 | ||
| 45 | /* Each of these macros verifies that its argument R is nonzero. To | 53 | /* Each of these macros verifies that its argument R is nonzero. To |
| 46 | be portable, R should be an integer constant expression. Unlike | 54 | be portable, R should be an integer constant expression. Unlike |
| @@ -143,50 +151,50 @@ | |||
| 143 | Use a template type to work around the problem. */ | 151 | Use a template type to work around the problem. */ |
| 144 | 152 | ||
| 145 | /* Concatenate two preprocessor tokens. */ | 153 | /* Concatenate two preprocessor tokens. */ |
| 146 | # define _GL_CONCAT(x, y) _GL_CONCAT0 (x, y) | 154 | #define _GL_CONCAT(x, y) _GL_CONCAT0 (x, y) |
| 147 | # define _GL_CONCAT0(x, y) x##y | 155 | #define _GL_CONCAT0(x, y) x##y |
| 148 | 156 | ||
| 149 | /* _GL_COUNTER is an integer, preferably one that changes each time we | 157 | /* _GL_COUNTER is an integer, preferably one that changes each time we |
| 150 | use it. Use __COUNTER__ if it works, falling back on __LINE__ | 158 | use it. Use __COUNTER__ if it works, falling back on __LINE__ |
| 151 | otherwise. __LINE__ isn't perfect, but it's better than a | 159 | otherwise. __LINE__ isn't perfect, but it's better than a |
| 152 | constant. */ | 160 | constant. */ |
| 153 | # if defined __COUNTER__ && __COUNTER__ != __COUNTER__ | 161 | #if defined __COUNTER__ && __COUNTER__ != __COUNTER__ |
| 154 | # define _GL_COUNTER __COUNTER__ | 162 | # define _GL_COUNTER __COUNTER__ |
| 155 | # else | 163 | #else |
| 156 | # define _GL_COUNTER __LINE__ | 164 | # define _GL_COUNTER __LINE__ |
| 157 | # endif | 165 | #endif |
| 158 | 166 | ||
| 159 | /* Generate a symbol with the given prefix, making it unique if | 167 | /* Generate a symbol with the given prefix, making it unique if |
| 160 | possible. */ | 168 | possible. */ |
| 161 | # define _GL_GENSYM(prefix) _GL_CONCAT (prefix, _GL_COUNTER) | 169 | #define _GL_GENSYM(prefix) _GL_CONCAT (prefix, _GL_COUNTER) |
| 162 | 170 | ||
| 163 | /* Verify requirement R at compile-time, as an integer constant expression | 171 | /* Verify requirement R at compile-time, as an integer constant expression |
| 164 | that returns 1. If R is false, fail at compile-time, preferably | 172 | that returns 1. If R is false, fail at compile-time, preferably |
| 165 | with a diagnostic that includes the string-literal DIAGNOSTIC. */ | 173 | with a diagnostic that includes the string-literal DIAGNOSTIC. */ |
| 166 | 174 | ||
| 167 | # define _GL_VERIFY_TRUE(R, DIAGNOSTIC) \ | 175 | #define _GL_VERIFY_TRUE(R, DIAGNOSTIC) \ |
| 168 | (!!sizeof (_GL_VERIFY_TYPE (R, DIAGNOSTIC))) | 176 | (!!sizeof (_GL_VERIFY_TYPE (R, DIAGNOSTIC))) |
| 169 | 177 | ||
| 170 | # ifdef __cplusplus | 178 | #ifdef __cplusplus |
| 171 | # if !GNULIB_defined_struct__gl_verify_type | 179 | # if !GNULIB_defined_struct__gl_verify_type |
| 172 | template <int w> | 180 | template <int w> |
| 173 | struct _gl_verify_type { | 181 | struct _gl_verify_type { |
| 174 | unsigned int _gl_verify_error_if_negative: w; | 182 | unsigned int _gl_verify_error_if_negative: w; |
| 175 | }; | 183 | }; |
| 176 | # define GNULIB_defined_struct__gl_verify_type 1 | 184 | # define GNULIB_defined_struct__gl_verify_type 1 |
| 177 | # endif | ||
| 178 | # define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \ | ||
| 179 | _gl_verify_type<(R) ? 1 : -1> | ||
| 180 | # elif defined _GL_HAVE__STATIC_ASSERT | ||
| 181 | # define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \ | ||
| 182 | struct { \ | ||
| 183 | _Static_assert (R, DIAGNOSTIC); \ | ||
| 184 | int _gl_dummy; \ | ||
| 185 | } | ||
| 186 | # else | ||
| 187 | # define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \ | ||
| 188 | struct { unsigned int _gl_verify_error_if_negative: (R) ? 1 : -1; } | ||
| 189 | # endif | 185 | # endif |
| 186 | # define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \ | ||
| 187 | _gl_verify_type<(R) ? 1 : -1> | ||
| 188 | #elif defined _GL_HAVE__STATIC_ASSERT | ||
| 189 | # define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \ | ||
| 190 | struct { \ | ||
| 191 | _Static_assert (R, DIAGNOSTIC); \ | ||
| 192 | int _gl_dummy; \ | ||
| 193 | } | ||
| 194 | #else | ||
| 195 | # define _GL_VERIFY_TYPE(R, DIAGNOSTIC) \ | ||
| 196 | struct { unsigned int _gl_verify_error_if_negative: (R) ? 1 : -1; } | ||
| 197 | #endif | ||
| 190 | 198 | ||
| 191 | /* Verify requirement R at compile-time, as a declaration without a | 199 | /* Verify requirement R at compile-time, as a declaration without a |
| 192 | trailing ';'. If R is false, fail at compile-time, preferably | 200 | trailing ';'. If R is false, fail at compile-time, preferably |
| @@ -195,23 +203,23 @@ template <int w> | |||
| 195 | Unfortunately, unlike C11, this implementation must appear as an | 203 | Unfortunately, unlike C11, this implementation must appear as an |
| 196 | ordinary declaration, and cannot appear inside struct { ... }. */ | 204 | ordinary declaration, and cannot appear inside struct { ... }. */ |
| 197 | 205 | ||
| 198 | # ifdef _GL_HAVE__STATIC_ASSERT | 206 | #ifdef _GL_HAVE__STATIC_ASSERT |
| 199 | # define _GL_VERIFY _Static_assert | 207 | # define _GL_VERIFY _Static_assert |
| 200 | # else | 208 | #else |
| 201 | # define _GL_VERIFY(R, DIAGNOSTIC) \ | 209 | # define _GL_VERIFY(R, DIAGNOSTIC) \ |
| 202 | extern int (*_GL_GENSYM (_gl_verify_function) (void)) \ | 210 | extern int (*_GL_GENSYM (_gl_verify_function) (void)) \ |
| 203 | [_GL_VERIFY_TRUE (R, DIAGNOSTIC)] | 211 | [_GL_VERIFY_TRUE (R, DIAGNOSTIC)] |
| 204 | # endif | 212 | #endif |
| 205 | 213 | ||
| 206 | /* _GL_STATIC_ASSERT_H is defined if this code is copied into assert.h. */ | 214 | /* _GL_STATIC_ASSERT_H is defined if this code is copied into assert.h. */ |
| 207 | # ifdef _GL_STATIC_ASSERT_H | 215 | #ifdef _GL_STATIC_ASSERT_H |
| 208 | # if !defined _GL_HAVE__STATIC_ASSERT && !defined _Static_assert | 216 | # if !defined _GL_HAVE__STATIC_ASSERT && !defined _Static_assert |
| 209 | # define _Static_assert(R, DIAGNOSTIC) _GL_VERIFY (R, DIAGNOSTIC) | 217 | # define _Static_assert(R, DIAGNOSTIC) _GL_VERIFY (R, DIAGNOSTIC) |
| 210 | # endif | 218 | # endif |
| 211 | # if !defined _GL_HAVE_STATIC_ASSERT && !defined static_assert | 219 | # if !defined _GL_HAVE_STATIC_ASSERT && !defined static_assert |
| 212 | # define static_assert _Static_assert /* C11 requires this #define. */ | 220 | # define static_assert _Static_assert /* C11 requires this #define. */ |
| 213 | # endif | ||
| 214 | # endif | 221 | # endif |
| 222 | #endif | ||
| 215 | 223 | ||
| 216 | /* @assert.h omit start@ */ | 224 | /* @assert.h omit start@ */ |
| 217 | 225 | ||
| @@ -229,18 +237,18 @@ template <int w> | |||
| 229 | 237 | ||
| 230 | verify_true is obsolescent; please use verify_expr instead. */ | 238 | verify_true is obsolescent; please use verify_expr instead. */ |
| 231 | 239 | ||
| 232 | # define verify_true(R) _GL_VERIFY_TRUE (R, "verify_true (" #R ")") | 240 | #define verify_true(R) _GL_VERIFY_TRUE (R, "verify_true (" #R ")") |
| 233 | 241 | ||
| 234 | /* Verify requirement R at compile-time. Return the value of the | 242 | /* Verify requirement R at compile-time. Return the value of the |
| 235 | expression E. */ | 243 | expression E. */ |
| 236 | 244 | ||
| 237 | # define verify_expr(R, E) \ | 245 | #define verify_expr(R, E) \ |
| 238 | (_GL_VERIFY_TRUE (R, "verify_expr (" #R ", " #E ")") ? (E) : (E)) | 246 | (_GL_VERIFY_TRUE (R, "verify_expr (" #R ", " #E ")") ? (E) : (E)) |
| 239 | 247 | ||
| 240 | /* Verify requirement R at compile-time, as a declaration without a | 248 | /* Verify requirement R at compile-time, as a declaration without a |
| 241 | trailing ';'. */ | 249 | trailing ';'. */ |
| 242 | 250 | ||
| 243 | # define verify(R) _GL_VERIFY (R, "verify (" #R ")") | 251 | #define verify(R) _GL_VERIFY (R, "verify (" #R ")") |
| 244 | 252 | ||
| 245 | /* @assert.h omit end@ */ | 253 | /* @assert.h omit end@ */ |
| 246 | 254 | ||