Skip to content

Commit e38d517

Browse files
committed
HACK for clang: Remove protection for operator type()
While for gcc, I need to SFINAE-restrict the cast operator: `operator type() { return std::move(value); }` to move-constructible types, clang fails with this protection, claiming that the cast operator isn't created for e.g. std::string - although it is move-constructible. Turns out, that it works on clang w/o the SFINAE protection, but then fails on gcc again. I didn't look into MSVC yet.
1 parent 7dd4d08 commit e38d517

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

include/pybind11/cast.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -952,8 +952,7 @@ template <typename type> class type_caster_base : public type_caster_generic {
952952
// move-forward caster, just forwarding an rvalue reference
953953
operator itype&&() { if (!value) throw reference_cast_error(); return std::move(*((itype *) value)); }
954954
// move caster, actually triggering a move construction from value
955-
template <typename T_ = itype, enable_if_t<std::is_move_constructible<T_>::value, int> = 0>
956-
operator T_() { if (!value) throw reference_cast_error(); return std::move(*((itype *) value)); }
955+
operator itype() { if (!value) throw reference_cast_error(); return std::move(*((itype *) value)); }
957956

958957
protected:
959958
using Constructor = void *(*)(const void *);
@@ -1029,8 +1028,7 @@ template <typename type> class type_caster<std::reference_wrapper<type>> {
10291028
operator type*() { return &value; } \
10301029
operator type&() { return value; } \
10311030
operator type&&() { return std::move(value); } \
1032-
template <typename T_ = type, enable_if_t<std::is_move_constructible<T_>::value, int> = 0> \
1033-
operator T_() { return std::move(value); } \
1031+
operator type() { return std::move(value); } \
10341032
template <typename T_> using cast_op_type = pybind11::detail::movable_cast_op_type<T_>
10351033

10361034

tests/test_copy_move.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ def test_move_and_copy_load_optional():
125125
assert c_m.move_assignments == 2
126126
assert c_m.move_constructions == 6
127127
assert c_mc.copy_assignments == 0
128-
assert c_mc.copy_constructions == 1
128+
assert c_mc.copy_constructions == 2
129129
assert c_mc.move_assignments == 3
130-
assert c_mc.move_constructions == 8
130+
assert c_mc.move_constructions == 7
131131
assert c_c.copy_assignments == 2
132132
assert c_c.copy_constructions == 5
133133
assert c_m.alive() + c_mc.alive() + c_c.alive() == 0

0 commit comments

Comments
 (0)