Skip to content

Commit a329095

Browse files
committed
Add additional static assert
1 parent f9863d1 commit a329095

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

tests/test_methods_and_attributes.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,17 @@ TEST_SUBMODULE(methods_and_attributes, m) {
566566
#endif
567567
;
568568

569+
// Verify that &&-qualified methods cannot be called on lvalues, only on rvalues.
570+
// This confirms that the cpp_function lambda must use std::move(*c).*f, not c->*f.
571+
#if __cplusplus >= 201703L
572+
static_assert(!std::is_invocable<std::string (RValueRefUnregisteredBase::*)() &&,
573+
RValueRefUnregisteredBase &>::value,
574+
"&&-qualified method must not be callable on lvalue");
575+
static_assert(std::is_invocable<std::string (RValueRefUnregisteredBase::*)() &&,
576+
RValueRefUnregisteredBase &&>::value,
577+
"&&-qualified method must be callable on rvalue");
578+
#endif
579+
569580
// Verify method_adaptor preserves &&/const&& qualifiers when rebinding.
570581
using AdaptedRRef = decltype(py::method_adaptor<RValueRefDerived>(&RValueRefDerived::take));
571582
static_assert(std::is_same<AdaptedRRef, std::string (RValueRefDerived::*)() &&>::value, "");

0 commit comments

Comments
 (0)