From 01b6ccb7fa186d730cf41c256203583edebe9e1d Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Sun, 18 Aug 2024 04:02:39 +0700 Subject: [PATCH] Move smart_holder POC code to tests/pure_cpp directory. (#5315) * Rename detail/smart_holder_poc.h -> struct_smart_holder.h * Establish (empty) tests/pure_cpp/smart_holder_poc.h * Move code guarded by `PYBIND11_TESTS_PURE_CPP_SMART_HOLDER_POC_TEST_CPP` from struct_smart_holder.h to tests/pure_cpp/smart_holder_poc.h --- CMakeLists.txt | 2 +- ...art_holder_poc.h => struct_smart_holder.h} | 55 +------------ include/pybind11/detail/type_caster_base.h | 2 +- include/pybind11/detail/using_smart_holder.h | 2 +- tests/extra_python_package/test_files.py | 2 +- tests/pure_cpp/smart_holder_poc.h | 51 ++++++++++++ tests/pure_cpp/smart_holder_poc_test.cpp | 81 ++++++++++--------- 7 files changed, 97 insertions(+), 98 deletions(-) rename include/pybind11/detail/{smart_holder_poc.h => struct_smart_holder.h} (85%) create mode 100644 tests/pure_cpp/smart_holder_poc.h diff --git a/CMakeLists.txt b/CMakeLists.txt index aa9634ee..d0f8f7e0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -133,7 +133,7 @@ set(PYBIND11_HEADERS include/pybind11/detail/dynamic_raw_ptr_cast_if_possible.h include/pybind11/detail/init.h include/pybind11/detail/internals.h - include/pybind11/detail/smart_holder_poc.h + include/pybind11/detail/struct_smart_holder.h include/pybind11/detail/type_caster_base.h include/pybind11/detail/typeid.h include/pybind11/detail/using_smart_holder.h diff --git a/include/pybind11/detail/smart_holder_poc.h b/include/pybind11/detail/struct_smart_holder.h similarity index 85% rename from include/pybind11/detail/smart_holder_poc.h rename to include/pybind11/detail/struct_smart_holder.h index 89742ab2..6fdd95f4 100644 --- a/include/pybind11/detail/smart_holder_poc.h +++ b/include/pybind11/detail/struct_smart_holder.h @@ -1,4 +1,4 @@ -// Copyright (c) 2020-2021 The Pybind Development Team. +// Copyright (c) 2020-2024 The Pybind Development Team. // All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. @@ -44,16 +44,6 @@ High-level aspects: * The `void_cast_raw_ptr` option is needed to make the `smart_holder` `vptr` member invisible to the `shared_from_this` mechanism, in case the lifetime of a `PyObject` is tied to the pointee. - -* Regarding `PYBIND11_TESTS_PURE_CPP_SMART_HOLDER_POC_TEST_CPP` below: - This define serves as a marker for code that is NOT used - from smart_holder_type_casters.h, but is exercised only from - tests/pure_cpp/smart_holder_poc_test.cpp. The marked code was useful - mainly for bootstrapping the smart_holder work. At this stage, with - smart_holder_type_casters.h in production use (at Google) since around - February 2021, it could be moved from here to tests/pure_cpp/ (help welcome). - It will probably be best in most cases to add tests for new functionality - under test/test_class_sh_*. */ #pragma once @@ -256,26 +246,6 @@ struct smart_holder { return static_cast(vptr.get()); } -#ifdef PYBIND11_TESTS_PURE_CPP_SMART_HOLDER_POC_TEST_CPP // See comment near top. - template - T &as_lvalue_ref() const { - static const char *context = "as_lvalue_ref"; - ensure_is_populated(context); - ensure_has_pointee(context); - return *as_raw_ptr_unowned(); - } -#endif - -#ifdef PYBIND11_TESTS_PURE_CPP_SMART_HOLDER_POC_TEST_CPP // See comment near top. - template - T &&as_rvalue_ref() const { - static const char *context = "as_rvalue_ref"; - ensure_is_populated(context); - ensure_has_pointee(context); - return std::move(*as_raw_ptr_unowned()); - } -#endif - template static smart_holder from_raw_ptr_take_ownership(T *raw_ptr, bool void_cast_raw_ptr = false) { ensure_pointee_is_destructible("from_raw_ptr_take_ownership"); @@ -319,16 +289,6 @@ struct smart_holder { release_disowned(); } -#ifdef PYBIND11_TESTS_PURE_CPP_SMART_HOLDER_POC_TEST_CPP // See comment near top. - template - T *as_raw_ptr_release_ownership(const char *context = "as_raw_ptr_release_ownership") { - ensure_can_release_ownership(context); - T *raw_ptr = as_raw_ptr_unowned(); - release_ownership(); - return raw_ptr; - } -#endif - template static smart_holder from_unique_ptr(std::unique_ptr &&unq_ptr, void *void_ptr = nullptr) { @@ -351,19 +311,6 @@ struct smart_holder { return hld; } -#ifdef PYBIND11_TESTS_PURE_CPP_SMART_HOLDER_POC_TEST_CPP // See comment near top. - template > - std::unique_ptr as_unique_ptr() { - static const char *context = "as_unique_ptr"; - ensure_compatible_rtti_uqp_del(context); - ensure_use_count_1(context); - T *raw_ptr = as_raw_ptr_unowned(); - release_ownership(); - // KNOWN DEFECT (see PR #4850): Does not copy the deleter. - return std::unique_ptr(raw_ptr); - } -#endif - template static smart_holder from_shared_ptr(std::shared_ptr shd_ptr) { smart_holder hld; diff --git a/include/pybind11/detail/type_caster_base.h b/include/pybind11/detail/type_caster_base.h index 92415718..cc62cfa8 100644 --- a/include/pybind11/detail/type_caster_base.h +++ b/include/pybind11/detail/type_caster_base.h @@ -789,7 +789,7 @@ struct load_helper : value_and_holder_helper { auto *gd = std::get_deleter(holder().vptr); if (gd && gd->use_del_fun) { // Note the ensure_compatible_rtti_uqp_del() call above. - // In smart_holder_poc, a custom deleter is always stored in a guarded delete. + // In struct_smart_holder, a custom deleter is always stored in a guarded delete. // The guarded delete's std::function actually points at the // custom_deleter type, so we can verify it is of the custom deleter type and // finally extract its deleter. diff --git a/include/pybind11/detail/using_smart_holder.h b/include/pybind11/detail/using_smart_holder.h index 3d046320..826e6b2c 100644 --- a/include/pybind11/detail/using_smart_holder.h +++ b/include/pybind11/detail/using_smart_holder.h @@ -10,7 +10,7 @@ #include #ifdef PYBIND11_HAS_INTERNALS_WITH_SMART_HOLDER_SUPPORT -# include "smart_holder_poc.h" +# include "struct_smart_holder.h" #endif PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) diff --git a/tests/extra_python_package/test_files.py b/tests/extra_python_package/test_files.py index e6602ad7..27c6f642 100644 --- a/tests/extra_python_package/test_files.py +++ b/tests/extra_python_package/test_files.py @@ -58,7 +58,7 @@ "include/pybind11/detail/dynamic_raw_ptr_cast_if_possible.h", "include/pybind11/detail/init.h", "include/pybind11/detail/internals.h", - "include/pybind11/detail/smart_holder_poc.h", + "include/pybind11/detail/struct_smart_holder.h", "include/pybind11/detail/type_caster_base.h", "include/pybind11/detail/typeid.h", "include/pybind11/detail/using_smart_holder.h", diff --git a/tests/pure_cpp/smart_holder_poc.h b/tests/pure_cpp/smart_holder_poc.h new file mode 100644 index 00000000..320311b7 --- /dev/null +++ b/tests/pure_cpp/smart_holder_poc.h @@ -0,0 +1,51 @@ +// Copyright (c) 2020-2024 The Pybind Development Team. +// All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +#pragma once + +#include "pybind11/detail/struct_smart_holder.h" + +namespace pybindit { +namespace memory { +namespace smart_holder_poc { // Proof-of-Concept implementations. + +template +T &as_lvalue_ref(const smart_holder &hld) { + static const char *context = "as_lvalue_ref"; + hld.ensure_is_populated(context); + hld.ensure_has_pointee(context); + return *hld.as_raw_ptr_unowned(); +} + +template +T &&as_rvalue_ref(const smart_holder &hld) { + static const char *context = "as_rvalue_ref"; + hld.ensure_is_populated(context); + hld.ensure_has_pointee(context); + return std::move(*hld.as_raw_ptr_unowned()); +} + +template +T *as_raw_ptr_release_ownership(smart_holder &hld, + const char *context = "as_raw_ptr_release_ownership") { + hld.ensure_can_release_ownership(context); + T *raw_ptr = hld.as_raw_ptr_unowned(); + hld.release_ownership(); + return raw_ptr; +} + +template > +std::unique_ptr as_unique_ptr(smart_holder &hld) { + static const char *context = "as_unique_ptr"; + hld.ensure_compatible_rtti_uqp_del(context); + hld.ensure_use_count_1(context); + T *raw_ptr = hld.as_raw_ptr_unowned(); + hld.release_ownership(); + // KNOWN DEFECT (see PR #4850): Does not copy the deleter. + return std::unique_ptr(raw_ptr); +} + +} // namespace smart_holder_poc +} // namespace memory +} // namespace pybindit diff --git a/tests/pure_cpp/smart_holder_poc_test.cpp b/tests/pure_cpp/smart_holder_poc_test.cpp index a9ad0364..24ab643e 100644 --- a/tests/pure_cpp/smart_holder_poc_test.cpp +++ b/tests/pure_cpp/smart_holder_poc_test.cpp @@ -1,6 +1,4 @@ -#define PYBIND11_TESTS_PURE_CPP_SMART_HOLDER_POC_TEST_CPP - -#include "pybind11/detail/smart_holder_poc.h" +#include "smart_holder_poc.h" #include #include @@ -16,6 +14,7 @@ #include "catch.hpp" using pybindit::memory::smart_holder; +namespace poc = pybindit::memory::smart_holder_poc; namespace helpers { @@ -70,14 +69,14 @@ TEST_CASE("from_raw_ptr_unowned+as_raw_ptr_unowned", "[S]") { TEST_CASE("from_raw_ptr_unowned+as_lvalue_ref", "[S]") { static int value = 19; auto hld = smart_holder::from_raw_ptr_unowned(&value); - REQUIRE(hld.as_lvalue_ref() == 19); + REQUIRE(poc::as_lvalue_ref(hld) == 19); } TEST_CASE("from_raw_ptr_unowned+as_rvalue_ref", "[S]") { helpers::movable_int orig(19); { auto hld = smart_holder::from_raw_ptr_unowned(&orig); - helpers::movable_int othr(hld.as_rvalue_ref()); + helpers::movable_int othr(poc::as_rvalue_ref(hld)); REQUIRE(othr.valu == 19); REQUIRE(orig.valu == 91); } @@ -86,21 +85,21 @@ TEST_CASE("from_raw_ptr_unowned+as_rvalue_ref", "[S]") { TEST_CASE("from_raw_ptr_unowned+as_raw_ptr_release_ownership", "[E]") { static int value = 19; auto hld = smart_holder::from_raw_ptr_unowned(&value); - REQUIRE_THROWS_WITH(hld.as_raw_ptr_release_ownership(), + REQUIRE_THROWS_WITH(poc::as_raw_ptr_release_ownership(hld), "Cannot disown non-owning holder (as_raw_ptr_release_ownership)."); } TEST_CASE("from_raw_ptr_unowned+as_unique_ptr", "[E]") { static int value = 19; auto hld = smart_holder::from_raw_ptr_unowned(&value); - REQUIRE_THROWS_WITH(hld.as_unique_ptr(), + REQUIRE_THROWS_WITH(poc::as_unique_ptr(hld), "Cannot disown non-owning holder (as_unique_ptr)."); } TEST_CASE("from_raw_ptr_unowned+as_unique_ptr_with_deleter", "[E]") { static int value = 19; auto hld = smart_holder::from_raw_ptr_unowned(&value); - REQUIRE_THROWS_WITH((hld.as_unique_ptr>()), + REQUIRE_THROWS_WITH((poc::as_unique_ptr>(hld)), "Missing unique_ptr deleter (as_unique_ptr)."); } @@ -113,12 +112,12 @@ TEST_CASE("from_raw_ptr_unowned+as_shared_ptr", "[S]") { TEST_CASE("from_raw_ptr_take_ownership+as_lvalue_ref", "[S]") { auto hld = smart_holder::from_raw_ptr_take_ownership(new int(19)); REQUIRE(hld.has_pointee()); - REQUIRE(hld.as_lvalue_ref() == 19); + REQUIRE(poc::as_lvalue_ref(hld) == 19); } TEST_CASE("from_raw_ptr_take_ownership+as_raw_ptr_release_ownership1", "[S]") { auto hld = smart_holder::from_raw_ptr_take_ownership(new int(19)); - auto new_owner = std::unique_ptr(hld.as_raw_ptr_release_ownership()); + auto new_owner = std::unique_ptr(poc::as_raw_ptr_release_ownership(hld)); REQUIRE(!hld.has_pointee()); REQUIRE(*new_owner == 19); } @@ -126,13 +125,13 @@ TEST_CASE("from_raw_ptr_take_ownership+as_raw_ptr_release_ownership1", "[S]") { TEST_CASE("from_raw_ptr_take_ownership+as_raw_ptr_release_ownership2", "[E]") { auto hld = smart_holder::from_raw_ptr_take_ownership(new int(19)); auto shd_ptr = hld.as_shared_ptr(); - REQUIRE_THROWS_WITH(hld.as_raw_ptr_release_ownership(), + REQUIRE_THROWS_WITH(poc::as_raw_ptr_release_ownership(hld), "Cannot disown use_count != 1 (as_raw_ptr_release_ownership)."); } TEST_CASE("from_raw_ptr_take_ownership+as_unique_ptr1", "[S]") { auto hld = smart_holder::from_raw_ptr_take_ownership(new int(19)); - std::unique_ptr new_owner = hld.as_unique_ptr(); + std::unique_ptr new_owner = poc::as_unique_ptr(hld); REQUIRE(!hld.has_pointee()); REQUIRE(*new_owner == 19); } @@ -140,12 +139,13 @@ TEST_CASE("from_raw_ptr_take_ownership+as_unique_ptr1", "[S]") { TEST_CASE("from_raw_ptr_take_ownership+as_unique_ptr2", "[E]") { auto hld = smart_holder::from_raw_ptr_take_ownership(new int(19)); auto shd_ptr = hld.as_shared_ptr(); - REQUIRE_THROWS_WITH(hld.as_unique_ptr(), "Cannot disown use_count != 1 (as_unique_ptr)."); + REQUIRE_THROWS_WITH(poc::as_unique_ptr(hld), + "Cannot disown use_count != 1 (as_unique_ptr)."); } TEST_CASE("from_raw_ptr_take_ownership+as_unique_ptr_with_deleter", "[E]") { auto hld = smart_holder::from_raw_ptr_take_ownership(new int(19)); - REQUIRE_THROWS_WITH((hld.as_unique_ptr>()), + REQUIRE_THROWS_WITH((poc::as_unique_ptr>(hld)), "Missing unique_ptr deleter (as_unique_ptr)."); } @@ -160,14 +160,14 @@ TEST_CASE("from_raw_ptr_take_ownership+disown+reclaim_disowned", "[S]") { auto hld = smart_holder::from_raw_ptr_take_ownership(new int(19)); std::unique_ptr new_owner(hld.as_raw_ptr_unowned()); hld.disown(); - REQUIRE(hld.as_lvalue_ref() == 19); + REQUIRE(poc::as_lvalue_ref(hld) == 19); REQUIRE(*new_owner == 19); hld.reclaim_disowned(); // Manually veriified: without this, clang++ -fsanitize=address reports // "detected memory leaks". // NOLINTNEXTLINE(bugprone-unused-return-value) (void) new_owner.release(); // Manually verified: without this, clang++ -fsanitize=address // reports "attempting double-free". - REQUIRE(hld.as_lvalue_ref() == 19); + REQUIRE(poc::as_lvalue_ref(hld) == 19); REQUIRE(new_owner.get() == nullptr); } @@ -175,7 +175,7 @@ TEST_CASE("from_raw_ptr_take_ownership+disown+release_disowned", "[S]") { auto hld = smart_holder::from_raw_ptr_take_ownership(new int(19)); std::unique_ptr new_owner(hld.as_raw_ptr_unowned()); hld.disown(); - REQUIRE(hld.as_lvalue_ref() == 19); + REQUIRE(poc::as_lvalue_ref(hld) == 19); REQUIRE(*new_owner == 19); hld.release_disowned(); REQUIRE(!hld.has_pointee()); @@ -195,14 +195,14 @@ TEST_CASE("from_unique_ptr+as_lvalue_ref", "[S]") { std::unique_ptr orig_owner(new int(19)); auto hld = smart_holder::from_unique_ptr(std::move(orig_owner)); REQUIRE(orig_owner.get() == nullptr); - REQUIRE(hld.as_lvalue_ref() == 19); + REQUIRE(poc::as_lvalue_ref(hld) == 19); } TEST_CASE("from_unique_ptr+as_raw_ptr_release_ownership1", "[S]") { std::unique_ptr orig_owner(new int(19)); auto hld = smart_holder::from_unique_ptr(std::move(orig_owner)); REQUIRE(orig_owner.get() == nullptr); - auto new_owner = std::unique_ptr(hld.as_raw_ptr_release_ownership()); + auto new_owner = std::unique_ptr(poc::as_raw_ptr_release_ownership(hld)); REQUIRE(!hld.has_pointee()); REQUIRE(*new_owner == 19); } @@ -212,7 +212,7 @@ TEST_CASE("from_unique_ptr+as_raw_ptr_release_ownership2", "[E]") { auto hld = smart_holder::from_unique_ptr(std::move(orig_owner)); REQUIRE(orig_owner.get() == nullptr); auto shd_ptr = hld.as_shared_ptr(); - REQUIRE_THROWS_WITH(hld.as_raw_ptr_release_ownership(), + REQUIRE_THROWS_WITH(poc::as_raw_ptr_release_ownership(hld), "Cannot disown use_count != 1 (as_raw_ptr_release_ownership)."); } @@ -220,7 +220,7 @@ TEST_CASE("from_unique_ptr+as_unique_ptr1", "[S]") { std::unique_ptr orig_owner(new int(19)); auto hld = smart_holder::from_unique_ptr(std::move(orig_owner)); REQUIRE(orig_owner.get() == nullptr); - std::unique_ptr new_owner = hld.as_unique_ptr(); + std::unique_ptr new_owner = poc::as_unique_ptr(hld); REQUIRE(!hld.has_pointee()); REQUIRE(*new_owner == 19); } @@ -230,14 +230,15 @@ TEST_CASE("from_unique_ptr+as_unique_ptr2", "[E]") { auto hld = smart_holder::from_unique_ptr(std::move(orig_owner)); REQUIRE(orig_owner.get() == nullptr); auto shd_ptr = hld.as_shared_ptr(); - REQUIRE_THROWS_WITH(hld.as_unique_ptr(), "Cannot disown use_count != 1 (as_unique_ptr)."); + REQUIRE_THROWS_WITH(poc::as_unique_ptr(hld), + "Cannot disown use_count != 1 (as_unique_ptr)."); } TEST_CASE("from_unique_ptr+as_unique_ptr_with_deleter", "[E]") { std::unique_ptr orig_owner(new int(19)); auto hld = smart_holder::from_unique_ptr(std::move(orig_owner)); REQUIRE(orig_owner.get() == nullptr); - REQUIRE_THROWS_WITH((hld.as_unique_ptr>()), + REQUIRE_THROWS_WITH((poc::as_unique_ptr>(hld)), "Incompatible unique_ptr deleter (as_unique_ptr)."); } @@ -254,7 +255,7 @@ TEST_CASE("from_unique_ptr_derived+as_unique_ptr_base", "[S]") { std::unique_ptr orig_owner(new helpers::derived()); auto hld = smart_holder::from_unique_ptr(std::move(orig_owner)); REQUIRE(orig_owner.get() == nullptr); - std::unique_ptr new_owner = hld.as_unique_ptr(); + std::unique_ptr new_owner = poc::as_unique_ptr(hld); REQUIRE(!hld.has_pointee()); REQUIRE(new_owner->get() == 100); } @@ -265,7 +266,7 @@ TEST_CASE("from_unique_ptr_derived+as_unique_ptr_base2", "[E]") { auto hld = smart_holder::from_unique_ptr(std::move(orig_owner)); REQUIRE(orig_owner.get() == nullptr); REQUIRE_THROWS_WITH( - (hld.as_unique_ptr>()), + (poc::as_unique_ptr>(hld)), "Incompatible unique_ptr deleter (as_unique_ptr)."); } @@ -273,7 +274,7 @@ TEST_CASE("from_unique_ptr_with_deleter+as_lvalue_ref", "[S]") { std::unique_ptr> orig_owner(new int(19)); auto hld = smart_holder::from_unique_ptr(std::move(orig_owner)); REQUIRE(orig_owner.get() == nullptr); - REQUIRE(hld.as_lvalue_ref() == 19); + REQUIRE(poc::as_lvalue_ref(hld) == 19); } TEST_CASE("from_unique_ptr_with_std_function_deleter+as_lvalue_ref", "[S]") { @@ -281,14 +282,14 @@ TEST_CASE("from_unique_ptr_with_std_function_deleter+as_lvalue_ref", "[S]") { new int(19), [](const int *raw_ptr) { delete raw_ptr; }); auto hld = smart_holder::from_unique_ptr(std::move(orig_owner)); REQUIRE(orig_owner.get() == nullptr); - REQUIRE(hld.as_lvalue_ref() == 19); + REQUIRE(poc::as_lvalue_ref(hld) == 19); } TEST_CASE("from_unique_ptr_with_deleter+as_raw_ptr_release_ownership", "[E]") { std::unique_ptr> orig_owner(new int(19)); auto hld = smart_holder::from_unique_ptr(std::move(orig_owner)); REQUIRE(orig_owner.get() == nullptr); - REQUIRE_THROWS_WITH(hld.as_raw_ptr_release_ownership(), + REQUIRE_THROWS_WITH(poc::as_raw_ptr_release_ownership(hld), "Cannot disown custom deleter (as_raw_ptr_release_ownership)."); } @@ -296,7 +297,7 @@ TEST_CASE("from_unique_ptr_with_deleter+as_unique_ptr", "[E]") { std::unique_ptr> orig_owner(new int(19)); auto hld = smart_holder::from_unique_ptr(std::move(orig_owner)); REQUIRE(orig_owner.get() == nullptr); - REQUIRE_THROWS_WITH(hld.as_unique_ptr(), + REQUIRE_THROWS_WITH(poc::as_unique_ptr(hld), "Incompatible unique_ptr deleter (as_unique_ptr)."); } @@ -305,7 +306,7 @@ TEST_CASE("from_unique_ptr_with_deleter+as_unique_ptr_with_deleter1", "[S]") { auto hld = smart_holder::from_unique_ptr(std::move(orig_owner)); REQUIRE(orig_owner.get() == nullptr); std::unique_ptr> new_owner - = hld.as_unique_ptr>(); + = poc::as_unique_ptr>(hld); REQUIRE(!hld.has_pointee()); REQUIRE(*new_owner == 19); } @@ -314,7 +315,7 @@ TEST_CASE("from_unique_ptr_with_deleter+as_unique_ptr_with_deleter2", "[E]") { std::unique_ptr> orig_owner(new int(19)); auto hld = smart_holder::from_unique_ptr(std::move(orig_owner)); REQUIRE(orig_owner.get() == nullptr); - REQUIRE_THROWS_WITH((hld.as_unique_ptr>()), + REQUIRE_THROWS_WITH((poc::as_unique_ptr>(hld)), "Incompatible unique_ptr deleter (as_unique_ptr)."); } @@ -330,27 +331,27 @@ TEST_CASE("from_unique_ptr_with_deleter+as_shared_ptr", "[S]") { TEST_CASE("from_shared_ptr+as_lvalue_ref", "[S]") { std::shared_ptr orig_owner(new int(19)); auto hld = smart_holder::from_shared_ptr(orig_owner); - REQUIRE(hld.as_lvalue_ref() == 19); + REQUIRE(poc::as_lvalue_ref(hld) == 19); } TEST_CASE("from_shared_ptr+as_raw_ptr_release_ownership", "[E]") { std::shared_ptr orig_owner(new int(19)); auto hld = smart_holder::from_shared_ptr(orig_owner); - REQUIRE_THROWS_WITH(hld.as_raw_ptr_release_ownership(), + REQUIRE_THROWS_WITH(poc::as_raw_ptr_release_ownership(hld), "Cannot disown external shared_ptr (as_raw_ptr_release_ownership)."); } TEST_CASE("from_shared_ptr+as_unique_ptr", "[E]") { std::shared_ptr orig_owner(new int(19)); auto hld = smart_holder::from_shared_ptr(orig_owner); - REQUIRE_THROWS_WITH(hld.as_unique_ptr(), + REQUIRE_THROWS_WITH(poc::as_unique_ptr(hld), "Cannot disown external shared_ptr (as_unique_ptr)."); } TEST_CASE("from_shared_ptr+as_unique_ptr_with_deleter", "[E]") { std::shared_ptr orig_owner(new int(19)); auto hld = smart_holder::from_shared_ptr(orig_owner); - REQUIRE_THROWS_WITH((hld.as_unique_ptr>()), + REQUIRE_THROWS_WITH((poc::as_unique_ptr>(hld)), "Missing unique_ptr deleter (as_unique_ptr)."); } @@ -362,19 +363,19 @@ TEST_CASE("from_shared_ptr+as_shared_ptr", "[S]") { TEST_CASE("error_unpopulated_holder", "[E]") { smart_holder hld; - REQUIRE_THROWS_WITH(hld.as_lvalue_ref(), "Unpopulated holder (as_lvalue_ref)."); + REQUIRE_THROWS_WITH(poc::as_lvalue_ref(hld), "Unpopulated holder (as_lvalue_ref)."); } TEST_CASE("error_disowned_holder", "[E]") { auto hld = smart_holder::from_raw_ptr_take_ownership(new int(19)); - hld.as_unique_ptr(); - REQUIRE_THROWS_WITH(hld.as_lvalue_ref(), "Disowned holder (as_lvalue_ref)."); + poc::as_unique_ptr(hld); + REQUIRE_THROWS_WITH(poc::as_lvalue_ref(hld), "Disowned holder (as_lvalue_ref)."); } TEST_CASE("error_cannot_disown_nullptr", "[E]") { auto hld = smart_holder::from_raw_ptr_take_ownership(new int(19)); - hld.as_unique_ptr(); - REQUIRE_THROWS_WITH(hld.as_unique_ptr(), "Cannot disown nullptr (as_unique_ptr)."); + poc::as_unique_ptr(hld); + REQUIRE_THROWS_WITH(poc::as_unique_ptr(hld), "Cannot disown nullptr (as_unique_ptr)."); } TEST_CASE("indestructible_int-from_raw_ptr_unowned+as_raw_ptr_unowned", "[S]") {