]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-91731: Don't define 'static_assert' in C++11 where is a keyword to avoid UB (GH...
authorPablo Galindo Salgado <Pablogsal@gmail.com>
Mon, 13 Jun 2022 14:49:08 +0000 (15:49 +0100)
committerGitHub <noreply@github.com>
Mon, 13 Jun 2022 14:49:08 +0000 (15:49 +0100)
Include/pymacro.h
Misc/NEWS.d/next/C API/2022-06-10-23-41-48.gh-issue-91731.fhYUQG.rst [new file with mode: 0644]

index 0a2c342e2c8aeefcdc201665989136572e722735..e37cda44c5ebf13e2632bf1d0dc12d7029528273 100644 (file)
 
 // static_assert is defined in glibc from version 2.16. Before it requires
 // compiler support (gcc >= 4.6) and is called _Static_assert.
+// 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))
 #  define static_assert _Static_assert
 #endif
diff --git a/Misc/NEWS.d/next/C API/2022-06-10-23-41-48.gh-issue-91731.fhYUQG.rst b/Misc/NEWS.d/next/C API/2022-06-10-23-41-48.gh-issue-91731.fhYUQG.rst
new file mode 100644 (file)
index 0000000..185671c
--- /dev/null
@@ -0,0 +1,3 @@
+Avoid defining the ``static_assert`` when compiling with C++ 11, where this
+is a keyword and redefining it can lead to undefined behavior. Patch by
+Pablo Galindo