Skip to content

Commit

Permalink
Follow-on to #30093 (correction) (#30098)
Browse files Browse the repository at this point in the history
* Bring back `std::addressof(src)` incorrectly removed with commit bcc40b2

Silly oversight: the `operator&() const` overload was missing in the test code.

* Change comment as suggested by @rainwoodman.
  • Loading branch information
Ralf W. Grosse-Kunstleve authored Feb 7, 2024
1 parent 54f8341 commit f468b2c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion include/pybind11/detail/smart_holder_type_casters.h
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ struct smart_holder_type_caster : smart_holder_type_caster_load<T>,
|| policy == return_value_policy::_clif_automatic) {
policy = return_value_policy::copy;
}
return cast(&src, policy, parent);
return cast(std::addressof(src), policy, parent);
// type_caster_base END
}

Expand Down
2 changes: 1 addition & 1 deletion include/pybind11/detail/type_caster_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,7 @@ class type_caster_base : public type_caster_generic {
|| policy == return_value_policy::automatic_reference) {
policy = return_value_policy::copy;
}
return cast(&src, policy, parent);
return cast(std::addressof(src), policy, parent);
}

static handle cast(itype &&src, return_value_policy, handle parent) {
Expand Down
4 changes: 3 additions & 1 deletion tests/pybind11_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ union IntFloat {
class UnusualOpRef {
public:
using NonTrivialType = std::shared_ptr<int>; // Almost any non-trivial type will do.
NonTrivialType operator&() { return non_trivial_member; } // UNUSUAL operator.
// Overriding operator& should not break pybind11.
NonTrivialType operator&() { return non_trivial_member; }
const NonTrivialType operator&() const { return non_trivial_member; }

private:
NonTrivialType non_trivial_member;
Expand Down

0 comments on commit f468b2c

Please sign in to comment.