Skip to content

Commit e75e612

Browse files
committed
pythongh-99069: Consolidate checks for static_assert
Several platforms don't define the static_assert macro despite having compiler support for the _Static_assert keyword. The macro needs to be defined since it is used unconditionally in the Python code. So it should always be safe to define it if undefined and not in C++11 (or later) mode. Hence, remove the checks for particular platforms or libc versions, and just define static_assert anytime it needs to be defined but isn't. That way, all platforms that need the fix will get it, regardless of whether someone specifically thought of them. Also document that certain macOS versions are among the platforms that need this.
1 parent cb2ef8b commit e75e612

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

Diff for: Include/pymacro.h

+9-11
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,18 @@
33

44
// gh-91782: On FreeBSD 12, if the _POSIX_C_SOURCE and _XOPEN_SOURCE macros are
55
// 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.
87
// 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
128

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.
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+
1515
// 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))
16+
#if !defined(static_assert) \
17+
&& !(defined(__cplusplus) && __cplusplus >= 201103L)
2018
# define static_assert _Static_assert
2119
#endif
2220

0 commit comments

Comments
 (0)