From 8e3132da79a143753011fa1e7bca063accf8220d Mon Sep 17 00:00:00 2001 From: Pablo Galindo Date: Fri, 10 Jun 2022 23:40:49 +0100 Subject: [PATCH 1/2] gh-91731: Don't define 'static_assert' in C++11 where is a keyword to avoid UB --- Include/pymacro.h | 2 +- .../2022-06-10-23-41-48.gh-issue-91731.fhYUQG.rst | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2022-06-10-23-41-48.gh-issue-91731.fhYUQG.rst diff --git a/Include/pymacro.h b/Include/pymacro.h index 0a2c342e2c8aee..bafeebd78205de 100644 --- a/Include/pymacro.h +++ b/Include/pymacro.h @@ -14,7 +14,7 @@ // compiler support (gcc >= 4.6) and is called _Static_assert. #if (defined(__GLIBC__) \ && (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ <= 16)) \ - && !defined(static_assert)) + && !defined(static_assert) && !(defined(__cplusplus) && __cplusplus >= 201103L)) # define static_assert _Static_assert #endif diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-06-10-23-41-48.gh-issue-91731.fhYUQG.rst b/Misc/NEWS.d/next/Core and Builtins/2022-06-10-23-41-48.gh-issue-91731.fhYUQG.rst new file mode 100644 index 00000000000000..185671ca4fcfb1 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2022-06-10-23-41-48.gh-issue-91731.fhYUQG.rst @@ -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 From 8f58dce4e984571091eb8869f890ef54a44f1ff2 Mon Sep 17 00:00:00 2001 From: Pablo Galindo Salgado Date: Sat, 11 Jun 2022 02:55:27 +0100 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> --- Include/pymacro.h | 4 +++- .../2022-06-10-23-41-48.gh-issue-91731.fhYUQG.rst | 0 2 files changed, 3 insertions(+), 1 deletion(-) rename Misc/NEWS.d/next/{Core and Builtins => C API}/2022-06-10-23-41-48.gh-issue-91731.fhYUQG.rst (100%) diff --git a/Include/pymacro.h b/Include/pymacro.h index bafeebd78205de..e37cda44c5ebf1 100644 --- a/Include/pymacro.h +++ b/Include/pymacro.h @@ -12,9 +12,11 @@ // 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(static_assert) && !(defined(__cplusplus) && __cplusplus >= 201103L)) + && !(defined(__cplusplus) && __cplusplus >= 201103L) \ + && !defined(static_assert)) # define static_assert _Static_assert #endif diff --git a/Misc/NEWS.d/next/Core and Builtins/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 similarity index 100% rename from Misc/NEWS.d/next/Core and Builtins/2022-06-10-23-41-48.gh-issue-91731.fhYUQG.rst rename to Misc/NEWS.d/next/C API/2022-06-10-23-41-48.gh-issue-91731.fhYUQG.rst