|
3 | 3 |
|
4 | 4 | // gh-91782: On FreeBSD 12, if the _POSIX_C_SOURCE and _XOPEN_SOURCE macros are
|
5 | 5 | // defined, <sys/cdefs.h> disables C11 support and <assert.h> does not define
|
6 |
| -// the static_assert() macro. Define the static_assert() macro in Python until |
7 |
| -// <sys/cdefs.h> suports C11: |
| 6 | +// the static_assert() macro. |
8 | 7 | // https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=255290
|
9 |
| -#if defined(__FreeBSD__) && !defined(static_assert) |
10 |
| -# define static_assert _Static_assert |
11 |
| -#endif |
12 |
| - |
13 |
| -// static_assert is defined in glibc from version 2.16. Before it requires |
14 |
| -// compiler support (gcc >= 4.6) and is called _Static_assert. |
15 |
| -// In C++ 11 static_assert is a keyword, redefining is undefined behaviour. |
16 |
| -#if (defined(__GLIBC__) \ |
17 |
| - && (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ <= 16)) \ |
18 |
| - && !(defined(__cplusplus) && __cplusplus >= 201103L) \ |
19 |
| - && !defined(static_assert)) |
| 8 | +// |
| 9 | +// macOS <= 10.10 doesn't define static_assert in assert.h at all despite |
| 10 | +// having C11 compiler support. |
| 11 | +// |
| 12 | +// static_assert is defined in glibc from version 2.16. Compiler support for |
| 13 | +// the C11 _Static_assert keyword is in gcc >= 4.6. |
| 14 | +// |
| 15 | +// MSVC makes static_assert a keyword in C11-17, contrary to the standards. |
| 16 | +// |
| 17 | +// In C++11 and C2x, static_assert is a keyword, redefining is undefined |
| 18 | +// behaviour. So only define if building as C (if __STDC_VERSION__ is defined), |
| 19 | +// not C++, and only for C11-17. |
| 20 | +#if !defined(static_assert) && (defined(__GNUC__) || defined(__clang__)) \ |
| 21 | + && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L \ |
| 22 | + && __STDC_VERSION__ <= 201710L |
20 | 23 | # define static_assert _Static_assert
|
21 | 24 | #endif
|
22 | 25 |
|
|
0 commit comments