Skip to content

Commit 7456109

Browse files
gh-91731: Don't define 'static_assert' in C++11 where is a keyword to avoid UB (GH-93700)
(cherry picked from commit 65ff27c) Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
1 parent 0c49a09 commit 7456109

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

Include/pymacro.h

+2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212

1313
// static_assert is defined in glibc from version 2.16. Before it requires
1414
// compiler support (gcc >= 4.6) and is called _Static_assert.
15+
// In C++ 11 static_assert is a keyword, redefining is undefined behaviour.
1516
#if (defined(__GLIBC__) \
1617
&& (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ <= 16)) \
18+
&& !(defined(__cplusplus) && __cplusplus >= 201103L) \
1719
&& !defined(static_assert))
1820
# define static_assert _Static_assert
1921
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Avoid defining the ``static_assert`` when compiling with C++ 11, where this
2+
is a keyword and redefining it can lead to undefined behavior. Patch by
3+
Pablo Galindo

0 commit comments

Comments
 (0)