From b72ca7d1bd8d07470b5094017c790f6c763f9b0f Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Wed, 28 Jul 2021 17:01:21 -0700 Subject: [PATCH] Removing MSVC C4100 from pragma block at the top of pybind11.h (#3150) * Removing pragma for 4100 (to see what is still broken with the latest code). * Adding --keep-going * Revert "Adding --keep-going" This reverts commit 1c844c6ffd07a6111b644811e7e3b0a50b9d44bb. * Introducing PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100. * _MSC_VER <= 1916 * Replacing simple variadic function with variadic template (attempt to resolve MSVC 2017 failures). * Preserving existing comment (moved from pybind11.h to detail/common.h). * Adding blank lines for readability. --- include/pybind11/attr.h | 5 +++++ include/pybind11/cast.h | 1 + include/pybind11/detail/common.h | 13 +++++++++++++ include/pybind11/detail/descr.h | 1 + include/pybind11/detail/init.h | 3 +++ include/pybind11/detail/type_caster_base.h | 2 ++ include/pybind11/pybind11.h | 3 ++- 7 files changed, 27 insertions(+), 1 deletion(-) diff --git a/include/pybind11/attr.h b/include/pybind11/attr.h index 60ed9fd90..20d119f0f 100644 --- a/include/pybind11/attr.h +++ b/include/pybind11/attr.h @@ -516,18 +516,22 @@ template struct process_attribute struct process_attributes { static void init(const Args&... args, function_record *r) { + PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(r); int unused[] = { 0, (process_attribute::type>::init(args, r), 0) ... }; ignore_unused(unused); } static void init(const Args&... args, type_record *r) { + PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(r); int unused[] = { 0, (process_attribute::type>::init(args, r), 0) ... }; ignore_unused(unused); } static void precall(function_call &call) { + PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(call); int unused[] = { 0, (process_attribute::type>::precall(call), 0) ... }; ignore_unused(unused); } static void postcall(function_call &call, handle fn_ret) { + PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(call, fn_ret); int unused[] = { 0, (process_attribute::type>::postcall(call, fn_ret), 0) ... }; ignore_unused(unused); } @@ -545,6 +549,7 @@ template ::value...), size_t self = constexpr_sum(std::is_same::value...)> constexpr bool expected_num_args(size_t nargs, bool has_args, bool has_kwargs) { + PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(nargs, has_args, has_kwargs); return named == 0 || (self + named + size_t(has_args) + size_t(has_kwargs)) == nargs; } diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 898047b30..5ff0355a6 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -605,6 +605,7 @@ protected: /* Implementation: Convert a C++ tuple into a Python tuple */ template static handle cast_impl(T &&src, return_value_policy policy, handle parent, index_sequence) { + PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(src, policy, parent); std::array entries{{ reinterpret_steal(make_caster::cast(std::get(std::forward(src)), policy, parent))... }}; diff --git a/include/pybind11/detail/common.h b/include/pybind11/detail/common.h index 0b4e30c18..0add6272f 100644 --- a/include/pybind11/detail/common.h +++ b/include/pybind11/detail/common.h @@ -913,5 +913,18 @@ inline static std::shared_ptr try_get_shared_from_this(std::enable_shared_fro #endif } +#if defined(_MSC_VER) && _MSC_VER <= 1916 + +// warning C4100: Unreferenced formal parameter +template +inline constexpr void workaround_incorrect_msvc_c4100(Args &&...) {} + +# define PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(...) \ + detail::workaround_incorrect_msvc_c4100(__VA_ARGS__) + +#else +# define PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(...) +#endif + PYBIND11_NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) diff --git a/include/pybind11/detail/descr.h b/include/pybind11/detail/descr.h index 7cb8350e7..0acfc7db3 100644 --- a/include/pybind11/detail/descr.h +++ b/include/pybind11/detail/descr.h @@ -42,6 +42,7 @@ struct descr { template constexpr descr plus_impl(const descr &a, const descr &b, index_sequence, index_sequence) { + PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(b); return {a.text[Is1]..., b.text[Is2]...}; } diff --git a/include/pybind11/detail/init.h b/include/pybind11/detail/init.h index 3269e0425..3ebec041f 100644 --- a/include/pybind11/detail/init.h +++ b/include/pybind11/detail/init.h @@ -94,6 +94,7 @@ void construct(...) { // construct an Alias from the returned base instance. template void construct(value_and_holder &v_h, Cpp *ptr, bool need_alias) { + PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(need_alias); no_nullptr(ptr); if (Class::has_alias && need_alias && !is_alias(ptr)) { // We're going to try to construct an alias by moving the cpp type. Whether or not @@ -131,6 +132,7 @@ void construct(value_and_holder &v_h, Alias *alias_ptr, bool) { // derived type (through those holder's implicit conversion from derived class holder constructors). template void construct(value_and_holder &v_h, Holder holder, bool need_alias) { + PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(need_alias); auto *ptr = holder_helper>::get(holder); no_nullptr(ptr); // If we need an alias, check that the held pointer is actually an alias instance @@ -148,6 +150,7 @@ void construct(value_and_holder &v_h, Holder holder, bool need_alias) { // need it, we simply move-construct the cpp value into a new instance. template void construct(value_and_holder &v_h, Cpp &&result, bool need_alias) { + PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(need_alias); static_assert(std::is_move_constructible>::value, "pybind11::init() return-by-value factory function requires a movable class"); if (Class::has_alias && need_alias) diff --git a/include/pybind11/detail/type_caster_base.h b/include/pybind11/detail/type_caster_base.h index 2a675418a..e2d1bcb8c 100644 --- a/include/pybind11/detail/type_caster_base.h +++ b/include/pybind11/detail/type_caster_base.h @@ -930,6 +930,7 @@ protected: does not have a private operator new implementation. */ template ::value>> static auto make_copy_constructor(const T *x) -> decltype(new T(*x), Constructor{}) { + PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(x); return [](const void *arg) -> void * { return new T(*reinterpret_cast(arg)); }; @@ -937,6 +938,7 @@ protected: template ::value>> static auto make_move_constructor(const T *x) -> decltype(new T(std::move(*const_cast(x))), Constructor{}) { + PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(x); return [](const void *arg) -> void * { return new T(std::move(*const_cast(reinterpret_cast(arg)))); }; diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index b14aff58a..139a4111e 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -12,7 +12,6 @@ #if defined(_MSC_VER) && !defined(__INTEL_COMPILER) # pragma warning(push) -# pragma warning(disable: 4100) // warning C4100: Unreferenced formal parameter # pragma warning(disable: 4127) // warning C4127: Conditional expression is constant # pragma warning(disable: 4505) // warning C4505: 'PySlice_GetIndicesEx': unreferenced local function has been removed (PyPy only) #elif defined(__GNUG__) && !defined(__clang__) && !defined(__INTEL_COMPILER) @@ -1388,12 +1387,14 @@ public: template class_ &def(const detail::initimpl::constructor &init, const Extra&... extra) { + PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(init); init.execute(*this, extra...); return *this; } template class_ &def(const detail::initimpl::alias_constructor &init, const Extra&... extra) { + PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(init); init.execute(*this, extra...); return *this; }