From d62d83dc32b2b50a7b0107d09a88ba5f1c7144f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Kul=C3=ADk?= Date: Thu, 18 Jul 2024 16:06:49 +0200 Subject: [PATCH 1/2] Fix check for static_assert for C++ on some platforms --- Include/pymacro.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Include/pymacro.h b/Include/pymacro.h index a7945ef84a46fc..c6d4fb0938717c 100644 --- a/Include/pymacro.h +++ b/Include/pymacro.h @@ -15,10 +15,10 @@ // MSVC makes static_assert a keyword in C11-17, contrary to the standards. // // In C++11 and C2x, static_assert is a keyword, redefining is undefined -// behaviour. So only define if building as C (if __STDC_VERSION__ is defined), -// not C++, and only for C11-17. +// behaviour. So only define if building as C, not C++ (if __cplusplus is +// not defined), and only for C11-17. #if !defined(static_assert) && (defined(__GNUC__) || defined(__clang__)) \ - && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L \ + && !defined(__cplusplus) && __STDC_VERSION__ >= 201112L \ && __STDC_VERSION__ <= 201710L # define static_assert _Static_assert #endif @@ -46,7 +46,7 @@ /* Argument must be a char or an int in [-128, 127] or [0, 255]. */ #define Py_CHARMASK(c) ((unsigned char)((c) & 0xff)) -#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L \ +#if (!defined(__cplusplus) && __STDC_VERSION__ >= 201112L \ && !defined(_MSC_VER)) # define Py_BUILD_ASSERT_EXPR(cond) \ ((void)sizeof(struct { int dummy; _Static_assert(cond, #cond); }), \ From 6cce4d5a7dc26fee1d1bff2a1c79bec1972d91d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Kul=C3=ADk?= Date: Fri, 19 Jul 2024 12:58:58 +0200 Subject: [PATCH 2/2] bring defined(__STDC_VERSION__) check back --- Include/pymacro.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Include/pymacro.h b/Include/pymacro.h index c6d4fb0938717c..e0378f9d27a048 100644 --- a/Include/pymacro.h +++ b/Include/pymacro.h @@ -18,8 +18,8 @@ // behaviour. So only define if building as C, not C++ (if __cplusplus is // not defined), and only for C11-17. #if !defined(static_assert) && (defined(__GNUC__) || defined(__clang__)) \ - && !defined(__cplusplus) && __STDC_VERSION__ >= 201112L \ - && __STDC_VERSION__ <= 201710L + && !defined(__cplusplus) && defined(__STDC_VERSION__) \ + && __STDC_VERSION__ >= 201112L && __STDC_VERSION__ <= 201710L # define static_assert _Static_assert #endif @@ -46,8 +46,8 @@ /* Argument must be a char or an int in [-128, 127] or [0, 255]. */ #define Py_CHARMASK(c) ((unsigned char)((c) & 0xff)) -#if (!defined(__cplusplus) && __STDC_VERSION__ >= 201112L \ - && !defined(_MSC_VER)) +#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L \ + && !defined(__cplusplus) && !defined(_MSC_VER)) # define Py_BUILD_ASSERT_EXPR(cond) \ ((void)sizeof(struct { int dummy; _Static_assert(cond, #cond); }), \ 0)