From 07ea833e6213bed0e2424e6420a233c923da9aac Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Thu, 5 Jun 2025 16:55:48 +0200 Subject: [PATCH 1/2] gh-135183: Suppress MSVC warning 5274 locally --- Include/Python.h | 13 ------------- Include/cpython/unicodeobject.h | 11 +++++++++++ Include/pymacro.h | 6 +++++- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/Include/Python.h b/Include/Python.h index f34d581f0b4c91..64be80145890a3 100644 --- a/Include/Python.h +++ b/Include/Python.h @@ -59,14 +59,6 @@ # include // __readgsqword() #endif -// Suppress known warnings in Python header files. -#if defined(_MSC_VER) -// Warning that alignas behaviour has changed. Doesn't affect us, because we -// never relied on the old behaviour. -#pragma warning(push) -#pragma warning(disable: 5274) -#endif - // Include Python header files #include "pyport.h" #include "pymacro.h" @@ -146,9 +138,4 @@ #include "cpython/pyfpe.h" #include "cpython/tracemalloc.h" -// Restore warning filter -#ifdef _MSC_VER -#pragma warning(pop) -#endif - #endif /* !Py_PYTHON_H */ diff --git a/Include/cpython/unicodeobject.h b/Include/cpython/unicodeobject.h index 3d0414f5291fe4..87bd8b0a3dfa96 100644 --- a/Include/cpython/unicodeobject.h +++ b/Include/cpython/unicodeobject.h @@ -47,6 +47,12 @@ static inline Py_UCS4 Py_UNICODE_LOW_SURROGATE(Py_UCS4 ch) { /* --- Unicode Type ------------------------------------------------------- */ +// Suppress known warning with _Py_ALIGN_AS; see gh-135183 +#if defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable: 5274) +#endif + /* ASCII-only strings created through PyUnicode_New use the PyASCIIObject structure. state.ascii and state.compact are set, and the data immediately follow the structure. utf8_length can be found @@ -162,6 +168,11 @@ typedef struct { } state; } PyASCIIObject; +// Restore warning filter +#ifdef _MSC_VER +#pragma warning(pop) +#endif + /* Non-ASCII strings allocated through PyUnicode_New use the PyCompactUnicodeObject structure. state.compact is set, and the data immediately follow the structure. */ diff --git a/Include/pymacro.h b/Include/pymacro.h index d410645034d848..e3740c3e267dae 100644 --- a/Include/pymacro.h +++ b/Include/pymacro.h @@ -24,7 +24,11 @@ #endif -// _Py_ALIGN_AS: this compiler's spelling of `alignas` keyword, +// _Py_ALIGN_AS: this compiler's spelling of `alignas` keyword. +// +// N.B. Applying this to a `struct` member might trigger MSVC warning 5274; +// see gh-135183 in that case. +// // We currently use alignas for free-threaded builds only; additional compat // checking would be great before we add it to the default build. // Standards/compiler support: From 06104a4993a4169d308578e98f2c6e8ad19054fd Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Fri, 6 Jun 2025 14:37:17 +0200 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Victor Stinner --- Include/cpython/unicodeobject.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Include/cpython/unicodeobject.h b/Include/cpython/unicodeobject.h index 87bd8b0a3dfa96..d447cafb31536c 100644 --- a/Include/cpython/unicodeobject.h +++ b/Include/cpython/unicodeobject.h @@ -49,8 +49,8 @@ static inline Py_UCS4 Py_UNICODE_LOW_SURROGATE(Py_UCS4 ch) { // Suppress known warning with _Py_ALIGN_AS; see gh-135183 #if defined(_MSC_VER) -#pragma warning(push) -#pragma warning(disable: 5274) +# pragma warning(push) +# pragma warning(disable: 5274) #endif /* ASCII-only strings created through PyUnicode_New use the PyASCIIObject @@ -170,7 +170,7 @@ typedef struct { // Restore warning filter #ifdef _MSC_VER -#pragma warning(pop) +# pragma warning(pop) #endif /* Non-ASCII strings allocated through PyUnicode_New use the