Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-99069: Consolidate checks for static_assert #94766

Merged
merged 9 commits into from
Apr 5, 2023
25 changes: 13 additions & 12 deletions Include/pymacro.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@

// gh-91782: On FreeBSD 12, if the _POSIX_C_SOURCE and _XOPEN_SOURCE macros are
// defined, <sys/cdefs.h> disables C11 support and <assert.h> does not define
// the static_assert() macro. Define the static_assert() macro in Python until
// <sys/cdefs.h> suports C11:
// the static_assert() macro.
// https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=255290
#if defined(__FreeBSD__) && !defined(static_assert)
# define static_assert _Static_assert
#endif

// static_assert is defined in glibc from version 2.16. Before it requires
// compiler support (gcc >= 4.6) and is called _Static_assert.
//
// macOS <= 10.10 doesn't define static_assert in assert.h at all despite
// having C11 compiler support.
//
// static_assert is defined in glibc from version 2.16. Compiler support for
// the C11 _Static_assert keyword is in gcc >= 4.6.
//
// MSVC makes static_assert a keyword, contrary to the C standard.
//
// In C++ 11 static_assert is a keyword, redefining is undefined behaviour.
#if (defined(__GLIBC__) \
&& (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ <= 16)) \
&& !(defined(__cplusplus) && __cplusplus >= 201103L) \
&& !defined(static_assert))
// So only define if building as C (if __STDC_VERSION__ is defined), not C++.
#if !defined(static_assert) && defined(__GNUC__) \
&& defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
# define static_assert _Static_assert
#endif

Expand Down