Skip to content

Commit fe60760

Browse files
unique_ptr: Resolve RobotLocomotion/drake#8160
1 parent ac2205a commit fe60760

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

include/pybind11/cast.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,6 +1630,22 @@ struct move_only_holder_caster : type_caster_base<type> {
16301630
using base::typeinfo;
16311631
using base::value;
16321632

1633+
// We must explicitly define the default constructor(s) since we define a
1634+
// destructor; otherwise, the compiler will incorrectly use the copy
1635+
// constructor.
1636+
move_only_holder_caster() = default;
1637+
move_only_holder_caster(move_only_holder_caster&&) = default;
1638+
move_only_holder_caster(const move_only_holder_caster&) = delete;
1639+
~move_only_holder_caster() {
1640+
if (holder) {
1641+
// If the argument was loaded into C++, but not transferred out,
1642+
// then this was most likely part of a failed overload in
1643+
// `argument_loader`. Transfer ownership back to Python.
1644+
move_only_holder_caster::cast(
1645+
std::move(holder), return_value_policy{}, handle{});
1646+
}
1647+
}
1648+
16331649
static_assert(std::is_base_of<type_caster_base<type>, type_caster<type>>::value,
16341650
"Holder classes are only supported for custom types");
16351651

0 commit comments

Comments
 (0)