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..d447cafb31536c 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: