Skip to content

Commit 351f0e3

Browse files
committed
Define _Py_ALIGN_AS for GCC on C++03 and below
1 parent 2451a86 commit 351f0e3

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Include/pymacro.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,22 @@
2727
// _Py_ALIGN_AS: this compiler's spelling of `alignas` keyword,
2828
// We currently use alignas for free-threaded builds only; additional compat
2929
// checking would be great before we add it to the default build.
30-
// Standards support:
30+
// Standards/compiler support:
3131
// - `alignas` is a keyword in C23 and C++11.
32-
// - `_Alignas` is a keyword in C11.
32+
// - `_Alignas` is a keyword in C11, and a common C compiler extension
33+
// - GCC & clang has __attribute__((aligned))
3334
// Older compilers may name it differently; to allow compilation on such
3435
// unsupported platforms, we don't redefine _Py_ALIGN_AS if it's already
3536
// defined. Note that defining it wrong (including defining it to nothing) will
3637
// cause ABI incompatibilities.
3738
#ifdef Py_GIL_DISABLED
3839
# ifndef _Py_ALIGN_AS
3940
# ifdef __cplusplus
40-
# define _Py_ALIGN_AS(V) alignas(V)
41+
# if (__cplusplus < 201103L) && (defined(__GNUC__) || defined(__clang__)
42+
# define _Py_ALIGN_AS(V) __attribute__((aligned(V)))
43+
# else
44+
# define _Py_ALIGN_AS(V) alignas(V)
45+
# endif
4146
# elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
4247
# define _Py_ALIGN_AS(V) alignas(V)
4348
# else

0 commit comments

Comments
 (0)