Skip to content

Commit a6dc1cc

Browse files
unique_ptr: Resolve RobotLocomotion/drake#8160
1 parent d16342c commit a6dc1cc

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
@@ -1551,6 +1551,22 @@ struct move_only_holder_caster : type_caster_base<type> {
15511551
using base::typeinfo;
15521552
using base::value;
15531553

1554+
// We must explicitly define the default constructor(s) since we define a
1555+
// destructor; otherwise, the compiler will incorrectly use the copy
1556+
// constructor.
1557+
move_only_holder_caster() = default;
1558+
move_only_holder_caster(move_only_holder_caster&&) = default;
1559+
move_only_holder_caster(const move_only_holder_caster&) = delete;
1560+
~move_only_holder_caster() {
1561+
if (holder) {
1562+
// If the argument was loaded into C++, but not transferred out,
1563+
// then this was most likely part of a failed overload in
1564+
// `argument_loader`. Transfer ownership back to Python.
1565+
move_only_holder_caster::cast(
1566+
std::move(holder), return_value_policy{}, handle{});
1567+
}
1568+
}
1569+
15541570
bool load(handle src, bool convert) {
15551571
return base::template load_impl<move_only_holder_caster<type, holder_type>>(src, convert);
15561572
}

0 commit comments

Comments
 (0)