]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-105059: Fix MSCV compiler warning on PyObject union (GH-107239) (#107248)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 25 Jul 2023 15:35:49 +0000 (08:35 -0700)
committerGitHub <noreply@github.com>
Tue, 25 Jul 2023 15:35:49 +0000 (15:35 +0000)
gh-105059: Fix MSCV compiler warning on PyObject union (GH-107239)

Use pragma to ignore the MSCV compiler warning on the PyObject
nameless union.
(cherry picked from commit 1c8fe9bdb624d356643ee569151a9e4f2963179a)

Co-authored-by: Victor Stinner <vstinner@python.org>
Include/object.h

index 542f8d8c15a7c74cc1738c066f6ce19af7fbd016..77434e3bc73c158cff37b746df45937cfff0cb58 100644 (file)
@@ -165,10 +165,17 @@ check by comparing the reference count field to the immortality reference count.
  */
 struct _object {
     _PyObject_HEAD_EXTRA
+
 #if (defined(__GNUC__) || defined(__clang__)) \
         && !(defined __STDC_VERSION__ && __STDC_VERSION__ >= 201112L)
     // On C99 and older, anonymous union is a GCC and clang extension
     __extension__
+#endif
+#ifdef _MSC_VER
+    // Ignore MSC warning C4201: "nonstandard extension used:
+    // nameless struct/union"
+    __pragma(warning(push))
+    __pragma(warning(disable: 4201))
 #endif
     union {
        Py_ssize_t ob_refcnt;
@@ -176,6 +183,10 @@ struct _object {
        PY_UINT32_T ob_refcnt_split[2];
 #endif
     };
+#ifdef _MSC_VER
+    __pragma(warning(pop))
+#endif
+
     PyTypeObject *ob_type;
 };