Skip to content

Commit

Permalink
Suppress unreferenced '_unused_op' warning
Browse files Browse the repository at this point in the history
On Windows, with cl /W4, we get following warning with Python 3.12:

  C:\Program Files\Python312\include\cpython/unicodeobject.h(203,57): warning C4100: '_unused_op': unreferenced formal parameter

Py_UNUSED hasn't changed in 5 years [1], but in Python 3.12 it started
being used in unicodeobject.h [2] so it became part of the public
interface. Because Py_UNUSED only prepended _unused_ to the parameter
name for MSVC [1], we get the C4100 warning when compiling with /W4.
In Python 3.13 this got fixed by adding a specific implementation of
Py_UNUSED for MSVC [3], so the warning is unique to Python 3.12.
However, as we don't know PY_VERSION_HEX _before_ including Python.h,
we'll indiscriminately suppress the C4100 while including Python.h.

[1] https://github.com/python/cpython/blame/3.12/Include/pymacro.h#L114-L123
[2] python/cpython@b2694ab
[3] python/cpython#107249
  • Loading branch information
bdegreve committed Aug 11, 2024
1 parent b19d9a8 commit 406ed45
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lass/python/python_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* The Original Developer is the Initial Developer.
*
* All portions of the code written by the Initial Developer are:
* Copyright (C) 2004-2011 the Initial Developer.
* Copyright (C) 2004-2024 the Initial Developer.
* All Rights Reserved.
*
* Contributor(s):
Expand Down Expand Up @@ -114,6 +114,13 @@
# undef _XOPEN_SOURCE
#endif

// Python 3.12 yields following warning in unicodeobject.h:
// warning C4100: '_unused_op': unreferenced formal parameter
#if LASS_COMPILER_TYPE == LASS_COMPILER_TYPE_MSVC
# pragma warning(push)
# pragma warning(disable: 4100) // unreferenced formal parameter
#endif

// Python >= 3.2 defines `PyType_Spec` in `object.h` which has a member called
// `slots`. When combining this with Qt, `slots` may already be defined as a
// macro. It is sufficient to temporarily undefine `slots` since this member
Expand All @@ -132,6 +139,10 @@

#pragma pop_macro("slots")

#if LASS_COMPILER_TYPE == LASS_COMPILER_TYPE_MSVC
# pragma warning(pop)
#endif

// oh r'ly? Because of some issue lost to ancient history, pyport.h will
// redefine following functions on FreeBSD > 500039 (and Apple?),
// causing really havoc with the C++ code.
Expand Down

0 comments on commit 406ed45

Please sign in to comment.