Skip to content

Commit

Permalink
gh-107249: Implement Py_UNUSED() for MSVC (#107250)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vstinner authored Jul 25, 2023
1 parent fabcbe9 commit 6a43cce
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Include/pymacro.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Implement the :c:macro:`Py_UNUSED` macro for Windows MSVC compiler. Patch by
Victor Stinner.

0 comments on commit 6a43cce

Please sign in to comment.