From 4fe34f2d095a9e77ef0a5dd0c3937113601dc426 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 22 Oct 2026 14:48:56 -0500 Subject: [PATCH] gh-160208: Fix _Py_ANONYMOUS on C++ Use __extension__ on g++/clang++ to fix this g++ warning on Include/object.h: error: ISO C++ prohibits anonymous structs [-Wpedantic] --- Include/pymacro.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Include/pymacro.h b/Include/pymacro.h index 41dfd9155b9b248..9e2d7bc21c0bed7 100644 --- a/Include/pymacro.h +++ b/Include/pymacro.h @@ -95,12 +95,13 @@ // - MSVC has warning(disable: 4201) "nonstandard extension used : nameless // struct/union". This is specific enough that we disable it for all of // Python.h. -// - GCC & clang needs __extension__ before C11 +// - GCC & clang needs __extension__ before C11 or on C++. // To allow unsupported platforms which need other spellings, we use a // predefined value of _Py_ANONYMOUS if it exists. #ifndef _Py_ANONYMOUS # if (defined(__GNUC__) || defined(__clang__)) \ - && !(defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) + && (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L \ + || defined(__cplusplus)) # define _Py_ANONYMOUS __extension__ # else # define _Py_ANONYMOUS