https://github.com/python/cpython/commit/f3a689fd9d5c762d92e43a7e1fb3ee7bfb27c452
commit: f3a689fd9d5c762d92e43a7e1fb3ee7bfb27c452
branch: 3.12
author: Miss Islington (bot) <[email protected]>
committer: vstinner <[email protected]>
date: 2024-12-13T11:58:47Z
summary:
[3.12] gh-107249: Implement Py_UNUSED() for MSVC (GH-107250) (#127907)
gh-107249: Implement Py_UNUSED() for MSVC (GH-107250)
Fix warnings C4100 in Py_UNUSED() when Python is built with "cl /W4".
Example with this function included by Python.h:
static inline unsigned int
PyUnicode_IS_READY(PyObject* Py_UNUSED(op))
{ return 1; }
Without this change, building a C program with "cl /W4" which just
includes Python.h emits the warning:
Include\cpython/unicodeobject.h(199):
warning C4100: '_unused_op': unreferenced formal parameter
This change fix this warning.
(cherry picked from commit 6a43cce32b66e0f66992119dd82959069b6f324a)
Co-authored-by: Victor Stinner <[email protected]>
files:
A Misc/NEWS.d/next/C API/2023-07-25-17-23-08.gh-issue-107249.xqk2ke.rst
M Include/pymacro.h
diff --git a/Include/pymacro.h b/Include/pymacro.h
index d5700dc38933c4..94e6248d2832cd 100644
--- a/Include/pymacro.h
+++ b/Include/pymacro.h
@@ -118,6 +118,15 @@
*/
#if defined(__GNUC__) || defined(__clang__)
# define Py_UNUSED(name) _unused_ ## name __attribute__((unused))
+#elif defined(_MSC_VER)
+ // Disable warning C4100: unreferenced formal parameter,
+ // declare the parameter,
+ // restore old compiler warnings.
+# define Py_UNUSED(name) \
+ __pragma(warning(push)) \
+ __pragma(warning(suppress: 4100)) \
+ _unused_ ## name \
+ __pragma(warning(pop))
#else
# define Py_UNUSED(name) _unused_ ## name
#endif
diff --git a/Misc/NEWS.d/next/C
API/2023-07-25-17-23-08.gh-issue-107249.xqk2ke.rst b/Misc/NEWS.d/next/C
API/2023-07-25-17-23-08.gh-issue-107249.xqk2ke.rst
new file mode 100644
index 00000000000000..a7139024329fae
--- /dev/null
+++ b/Misc/NEWS.d/next/C API/2023-07-25-17-23-08.gh-issue-107249.xqk2ke.rst
@@ -0,0 +1,2 @@
+Implement the :c:macro:`Py_UNUSED` macro for Windows MSVC compiler. Patch by
+Victor Stinner.
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]