Skip to content

Commit f468b2c

Browse files
authored
Follow-on to #30093 (correction) (#30098)
* 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.
1 parent 54f8341 commit f468b2c

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

include/pybind11/detail/smart_holder_type_casters.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ struct smart_holder_type_caster : smart_holder_type_caster_load<T>,
757757
|| policy == return_value_policy::_clif_automatic) {
758758
policy = return_value_policy::copy;
759759
}
760-
return cast(&src, policy, parent);
760+
return cast(std::addressof(src), policy, parent);
761761
// type_caster_base END
762762
}
763763

include/pybind11/detail/type_caster_base.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,7 @@ class type_caster_base : public type_caster_generic {
11161116
|| policy == return_value_policy::automatic_reference) {
11171117
policy = return_value_policy::copy;
11181118
}
1119-
return cast(&src, policy, parent);
1119+
return cast(std::addressof(src), policy, parent);
11201120
}
11211121

11221122
static handle cast(itype &&src, return_value_policy, handle parent) {

tests/pybind11_tests.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ union IntFloat {
5757
class UnusualOpRef {
5858
public:
5959
using NonTrivialType = std::shared_ptr<int>; // Almost any non-trivial type will do.
60-
NonTrivialType operator&() { return non_trivial_member; } // UNUSUAL operator.
60+
// Overriding operator& should not break pybind11.
61+
NonTrivialType operator&() { return non_trivial_member; }
62+
const NonTrivialType operator&() const { return non_trivial_member; }
6163

6264
private:
6365
NonTrivialType non_trivial_member;

0 commit comments

Comments
 (0)