Skip to content

Commit 0e0669d

Browse files
committed
Try to resolve MSVC C4003 warning
1 parent a329095 commit 0e0669d

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

include/pybind11/pybind11.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1980,14 +1980,20 @@ struct rebind_member_ptr {};
19801980
// Define one specialization per supported qualifier combination via a local macro.
19811981
// The qualifiers argument appears in type position, not expression position, so
19821982
// parenthesizing it would produce invalid C++.
1983+
// The no-qualifier specialization is written out explicitly to avoid invoking the macro with an
1984+
// empty argument, which triggers MSVC warning C4003.
1985+
template <typename Derived, typename Return, typename Class, typename... Args>
1986+
struct rebind_member_ptr<Derived, Return (Class::*)(Args...)> {
1987+
using type = Return (Derived::*)(Args...);
1988+
using source_class = Class;
1989+
};
19831990
// NOLINTBEGIN(bugprone-macro-parentheses)
19841991
#define PYBIND11_REBIND_MEMBER_PTR(qualifiers) \
19851992
template <typename Derived, typename Return, typename Class, typename... Args> \
19861993
struct rebind_member_ptr<Derived, Return (Class::*)(Args...) qualifiers> { \
19871994
using type = Return (Derived::*)(Args...) qualifiers; \
19881995
using source_class = Class; \
19891996
}
1990-
PYBIND11_REBIND_MEMBER_PTR();
19911997
PYBIND11_REBIND_MEMBER_PTR(const);
19921998
PYBIND11_REBIND_MEMBER_PTR(&);
19931999
PYBIND11_REBIND_MEMBER_PTR(const &);
@@ -2029,6 +2035,12 @@ constexpr auto method_adaptor(F &&f) -> decltype(std::forward<F>(f)) {
20292035
// One thin overload per supported member-function-pointer qualifier combination.
20302036
// Specific parameter types are required so partial ordering prefers these over the F&& fallback.
20312037
// The shared body (static_assert + implicit cast) lives in detail::adapt_member_ptr.
2038+
// The no-qualifier overload is written out explicitly to avoid invoking the macro with an empty
2039+
// argument, which triggers MSVC warning C4003.
2040+
template <typename Derived, typename Return, typename Class, typename... Args>
2041+
constexpr auto method_adaptor(Return (Class::*pmf)(Args...)) -> Return (Derived::*)(Args...) {
2042+
return detail::adapt_member_ptr<Derived>(pmf);
2043+
}
20322044
// The qualifiers argument appears in type position, not expression position, so
20332045
// parenthesizing it would produce invalid C++.
20342046
// NOLINTBEGIN(bugprone-macro-parentheses)
@@ -2038,7 +2050,6 @@ constexpr auto method_adaptor(F &&f) -> decltype(std::forward<F>(f)) {
20382050
-> Return (Derived::*)(Args...) qualifiers { \
20392051
return detail::adapt_member_ptr<Derived>(pmf); \
20402052
}
2041-
PYBIND11_METHOD_ADAPTOR()
20422053
PYBIND11_METHOD_ADAPTOR(const)
20432054
PYBIND11_METHOD_ADAPTOR(&)
20442055
PYBIND11_METHOD_ADAPTOR(const &)

0 commit comments

Comments
 (0)