Skip to content

Commit

Permalink
Removing operator T&&() && from smart_holder_type_caster, for compa…
Browse files Browse the repository at this point in the history
…tibility with the behavior of type_caster_base. Enables reverting 2 of 3 test manipulations applied under commit 249df7c. The manipulation in test_factory_constructors.py is NOT reverted in this commit.

[skip ci]
  • Loading branch information
Ralf W. Grosse-Kunstleve committed Feb 12, 2021
1 parent 67c2910 commit 23036a4
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
14 changes: 5 additions & 9 deletions include/pybind11/cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -1385,19 +1385,15 @@ struct smart_holder_type_caster : smart_holder_type_caster_load<T>,
using cast_op_type = conditional_t<
std::is_same<remove_reference_t<T_>, T const *>::value,
T const *,
conditional_t<
std::is_same<remove_reference_t<T_>, T *>::value,
T *,
conditional_t<std::is_same<T_, T const &>::value,
T const &,
conditional_t<std::is_same<T_, T &>::value,
T &,
conditional_t<std::is_same<T_, T &&>::value, T &&, T>>>>>;
conditional_t<std::is_same<remove_reference_t<T_>, T *>::value,
T *,
conditional_t<std::is_same<T_, T const &>::value,
T const &,
conditional_t<std::is_same<T_, T &>::value, T &, T>>>>;

// clang-format off

operator T() { return this->loaded_as_lvalue_ref(); }
operator T&&() && { return this->loaded_as_rvalue_ref(); }
operator T const&() { return this->loaded_as_lvalue_ref(); }
operator T&() { return this->loaded_as_lvalue_ref(); }
operator T const*() { return this->loaded_as_raw_ptr_unowned(); }
Expand Down
4 changes: 2 additions & 2 deletions tests/test_class_sh_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def test_cast():


def test_load():
assert m.pass_valu_atyp(m.atyp("Valu")) == "pass_valu:Valu.MvCtor.MvCtor"
assert m.pass_rref_atyp(m.atyp("Rref")) == "pass_rref:Rref.MvCtor"
assert m.pass_valu_atyp(m.atyp("Valu")) == "pass_valu:Valu.MvCtor.CpCtor"
assert m.pass_rref_atyp(m.atyp("Rref")) == "pass_rref:Rref.MvCtor.CpCtor"
assert m.pass_cref_atyp(m.atyp("Cref")) == "pass_cref:Cref.MvCtor"
assert m.pass_mref_atyp(m.atyp("Mref")) == "pass_mref:Mref.MvCtor"
assert m.pass_cptr_atyp(m.atyp("Cptr")) == "pass_cptr:Cptr.MvCtor"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_methods_and_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_methods_and_attributes():
assert cstats.alive() == 0
assert cstats.values() == ["32"]
assert cstats.default_constructions == 1
assert cstats.copy_constructions in (2, 1) # SMART_HOLDER_WIP
assert cstats.copy_constructions == 2
assert cstats.move_constructions >= 2
assert cstats.copy_assignments == 0
assert cstats.move_assignments == 0
Expand Down
2 changes: 1 addition & 1 deletion tests/test_virtual_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def get_movable(self, a, b):
assert nc_stats.values() == ["4", "9", "9", "9"]
assert mv_stats.values() == ["4", "5", "7", "7"]
assert nc_stats.copy_constructions == 0
assert mv_stats.copy_constructions in (1, 0) # SMART_HOLDER_WIP
assert mv_stats.copy_constructions == 1
assert nc_stats.move_constructions >= 0
assert mv_stats.move_constructions >= 0

Expand Down

0 comments on commit 23036a4

Please sign in to comment.