From 406ed45587c3f6ca9f5b5eb7975daa56de6cf800 Mon Sep 17 00:00:00 2001 From: Bram de Greve Date: Sat, 10 Aug 2024 19:26:58 +0200 Subject: [PATCH] Suppress unreferenced '_unused_op' warning 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] https://github.com/python/cpython/commit/b2694ab46997746eae7e913738623b39f6334473 [3] https://github.com/python/cpython/issues/107249 --- lass/python/python_common.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lass/python/python_common.h b/lass/python/python_common.h index 6c9e02ef..1a352682 100644 --- a/lass/python/python_common.h +++ b/lass/python/python_common.h @@ -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): @@ -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 @@ -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.