diff --git a/include/pybind11/smart_holder_poc.h b/include/pybind11/smart_holder_poc.h index bdde8d891..a3a85243c 100644 --- a/include/pybind11/smart_holder_poc.h +++ b/include/pybind11/smart_holder_poc.h @@ -90,6 +90,20 @@ struct smart_holder { } } + template + void from_raw_ptr_unowned(T* raw_ptr) { + clear(); + rtti_held = &typeid(T); + vptr.reset(raw_ptr, guarded_builtin_delete(&vptr_deleter_guard_flag)); + } + + template + T* as_raw_ptr_unowned() const { + static const char* context = "as_raw_ptr_unowned"; + ensure_compatible_rtti_held(context); + return static_cast(vptr.get()); + } + template const T& const_value_ref() const { static const char* context = "const_value_ref"; @@ -107,13 +121,6 @@ struct smart_holder { vptr.reset(raw_ptr, guarded_builtin_delete(&vptr_deleter_guard_flag)); } - template - void from_raw_ptr_unowned(T* raw_ptr) { - clear(); - rtti_held = &typeid(T); - vptr.reset(raw_ptr, guarded_builtin_delete(&vptr_deleter_guard_flag)); - } - template T* as_raw_ptr_release_ownership( const char* context = "as_raw_ptr_release_ownership") { @@ -126,13 +133,6 @@ struct smart_holder { return raw_ptr; } - template - T* as_raw_ptr_unowned() const { - static const char* context = "as_raw_ptr_unowned"; - ensure_compatible_rtti_held(context); - return static_cast(vptr.get()); - } - template void from_unique_ptr(std::unique_ptr&& unq_ptr) { clear(); diff --git a/tests/core/smart_holder_poc_test.cpp b/tests/core/smart_holder_poc_test.cpp index ded88e001..9dad8c2bb 100644 --- a/tests/core/smart_holder_poc_test.cpp +++ b/tests/core/smart_holder_poc_test.cpp @@ -14,22 +14,36 @@ struct functor_builtin_delete { } // namespace helpers -TEST_CASE("from_raw_ptr_take_ownership+const_value_ref", "[feasible]") { - smart_holder hld; - REQUIRE(!hld.has_pointee()); - hld.from_raw_ptr_take_ownership(new int(19)); - REQUIRE(hld.has_pointee()); - REQUIRE(hld.const_value_ref() == 19); +TEST_CASE("from_raw_ptr_unowned+as_raw_ptr_unowned", "[S]") { } -TEST_CASE("from_raw_ptr_unowned+const_value_ref", "[feasible]") { +TEST_CASE("from_raw_ptr_unowned+const_value_ref", "[S]") { static int value = 19; smart_holder hld; hld.from_raw_ptr_unowned(&value); REQUIRE(hld.const_value_ref() == 19); } -TEST_CASE("from_raw_ptr_take_ownership+as_raw_ptr_release_ownership", "[feasible]") { +TEST_CASE("from_raw_ptr_unowned+as_raw_ptr_release_ownership", "[E]") { +} + +TEST_CASE("from_raw_ptr_unowned+as_unique_ptr", "[E]") { +} + +TEST_CASE("from_raw_ptr_unowned+as_unique_ptr_with_deleter", "[E]") { +} + +TEST_CASE("from_raw_ptr_unowned+as_shared_ptr", "[S]") { +} + +TEST_CASE("from_raw_ptr_take_ownership+const_value_ref", "[S]") { + smart_holder hld; + hld.from_raw_ptr_take_ownership(new int(19)); + REQUIRE(hld.has_pointee()); + REQUIRE(hld.const_value_ref() == 19); +} + +TEST_CASE("from_raw_ptr_take_ownership+as_raw_ptr_release_ownership1", "[S]") { smart_holder hld; hld.from_raw_ptr_take_ownership(new int(19)); auto new_owner = @@ -37,23 +51,10 @@ TEST_CASE("from_raw_ptr_take_ownership+as_raw_ptr_release_ownership", "[feasible REQUIRE(!hld.has_pointee()); } -TEST_CASE("from_raw_ptr_take_ownership+as_raw_ptr_unowned", "[feasible]") { - smart_holder hld; - hld.from_raw_ptr_take_ownership(new int(19)); - int* raw_ptr = hld.as_raw_ptr_unowned(); - REQUIRE(hld.has_pointee()); - REQUIRE(*raw_ptr == 19); +TEST_CASE("from_raw_ptr_take_ownership+as_raw_ptr_release_ownership2", "[E]") { } -TEST_CASE("from_unique_ptr+const_value_ref+const_value_ref", "[feasible]") { - std::unique_ptr orig_owner(new int(19)); - smart_holder hld; - hld.from_unique_ptr(std::move(orig_owner)); - REQUIRE(orig_owner.get() == nullptr); - REQUIRE(hld.const_value_ref() == 19); -} - -TEST_CASE("from_raw_ptr_take_ownership+as_unique_ptr", "[feasible]") { +TEST_CASE("from_raw_ptr_take_ownership+as_unique_ptr1", "[S]") { smart_holder hld; hld.from_raw_ptr_take_ownership(new int(19)); auto new_owner = hld.as_unique_ptr(); @@ -61,7 +62,47 @@ TEST_CASE("from_raw_ptr_take_ownership+as_unique_ptr", "[feasible]") { REQUIRE(*new_owner == 19); } -TEST_CASE("from_unique_ptr_with_deleter+const_value_ref", "[feasible]") { +TEST_CASE("from_raw_ptr_take_ownership+as_unique_ptr2", "[E]") { +} + +TEST_CASE("from_raw_ptr_take_ownership+as_unique_ptr_with_deleter", "[E]") { +} + +TEST_CASE("from_raw_ptr_take_ownership+as_shared_ptr", "[S]") { + smart_holder hld; + hld.from_raw_ptr_take_ownership(new int(19)); + auto new_owner = hld.as_shared_ptr(); + REQUIRE(hld.has_pointee()); + REQUIRE(*new_owner == 19); +} + +TEST_CASE("from_unique_ptr+const_value_ref", "[S]") { + std::unique_ptr orig_owner(new int(19)); + smart_holder hld; + hld.from_unique_ptr(std::move(orig_owner)); + REQUIRE(orig_owner.get() == nullptr); + REQUIRE(hld.const_value_ref() == 19); +} + +TEST_CASE("from_unique_ptr+as_raw_ptr_release_ownership1", "[S]") { +} + +TEST_CASE("from_unique_ptr+as_raw_ptr_release_ownership2", "[E]") { +} + +TEST_CASE("from_unique_ptr+as_unique_ptr1", "[S]") { +} + +TEST_CASE("from_unique_ptr+as_unique_ptr2", "[E]") { +} + +TEST_CASE("from_unique_ptr+as_unique_ptr_with_deleter", "[E]") { +} + +TEST_CASE("from_unique_ptr+as_shared_ptr", "[S]") { +} + +TEST_CASE("from_unique_ptr_with_deleter+const_value_ref", "[S]") { std::unique_ptr> orig_owner( new int(19)); smart_holder hld; @@ -70,7 +111,13 @@ TEST_CASE("from_unique_ptr_with_deleter+const_value_ref", "[feasible]") { REQUIRE(hld.const_value_ref() == 19); } -TEST_CASE("from_unique_ptr_with_deleter+as_unique_ptr_with_deleter", "[feasible]") { +TEST_CASE("from_unique_ptr_with_deleter+as_raw_ptr_release_ownership", "[E]") { +} + +TEST_CASE("from_unique_ptr_with_deleter+as_unique_ptr", "[E]") { +} + +TEST_CASE("from_unique_ptr_with_deleter+as_unique_ptr_with_deleter1", "[S]") { std::unique_ptr> orig_owner( new int(19)); smart_holder hld; @@ -82,7 +129,13 @@ TEST_CASE("from_unique_ptr_with_deleter+as_unique_ptr_with_deleter", "[feasible] REQUIRE(*new_owner == 19); } -TEST_CASE("from_shared_ptr+const_value_ref", "[feasible]") { +TEST_CASE("from_unique_ptr_with_deleter+as_unique_ptr_with_deleter2", "[E]") { +} + +TEST_CASE("from_unique_ptr_with_deleter+as_shared_ptr", "[S]") { +} + +TEST_CASE("from_shared_ptr+const_value_ref", "[S]") { std::shared_ptr orig_owner(new int(19)); smart_holder hld; hld.from_shared_ptr(orig_owner); @@ -90,10 +143,17 @@ TEST_CASE("from_shared_ptr+const_value_ref", "[feasible]") { REQUIRE(hld.const_value_ref() == 19); } -TEST_CASE("from_raw_ptr_take_ownership+as_shared_ptr", "[feasible]") { - smart_holder hld; - hld.from_raw_ptr_take_ownership(new int(19)); - auto new_owner = hld.as_shared_ptr(); - REQUIRE(hld.has_pointee()); - REQUIRE(*new_owner == 19); +TEST_CASE("from_shared_ptr+as_raw_ptr_release_ownership1", "[S]") { +} + +TEST_CASE("from_shared_ptr+as_raw_ptr_release_ownership2", "[E]") { +} + +TEST_CASE("from_shared_ptr+as_unique_ptr", "[E]") { +} + +TEST_CASE("from_shared_ptr+as_unique_ptr_with_deleter", "[E]") { +} + +TEST_CASE("from_shared_ptr+as_shared_ptr", "[S]") { }