Pure clang-format --style=file -i change.

This commit is contained in:
Ralf W. Grosse-Kunstleve 2021-01-12 10:28:17 -08:00
parent cfc848a137
commit e7aea026bb
2 changed files with 340 additions and 379 deletions

View File

@ -49,20 +49,20 @@ namespace memory {
template <typename T> template <typename T>
struct guarded_builtin_delete { struct guarded_builtin_delete {
bool *flag_ptr; bool *flag_ptr;
explicit guarded_builtin_delete(bool* guard_flag_ptr) explicit guarded_builtin_delete(bool *guard_flag_ptr) : flag_ptr{guard_flag_ptr} {}
: flag_ptr{guard_flag_ptr} {}
void operator()(T *raw_ptr) { void operator()(T *raw_ptr) {
if (*flag_ptr) delete raw_ptr; if (*flag_ptr)
delete raw_ptr;
} }
}; };
template <typename T, typename D> template <typename T, typename D>
struct guarded_custom_deleter { struct guarded_custom_deleter {
bool *flag_ptr; bool *flag_ptr;
explicit guarded_custom_deleter(bool* guard_flag_ptr) explicit guarded_custom_deleter(bool *guard_flag_ptr) : flag_ptr{guard_flag_ptr} {}
: flag_ptr{guard_flag_ptr} {}
void operator()(T *raw_ptr) { void operator()(T *raw_ptr) {
if (*flag_ptr) D()(raw_ptr); if (*flag_ptr)
D()(raw_ptr);
} }
}; };
@ -76,11 +76,8 @@ struct smart_holder {
bool vptr_is_external_shared_ptr : 1; bool vptr_is_external_shared_ptr : 1;
smart_holder() smart_holder()
: rtti_held{nullptr}, : rtti_held{nullptr}, rtti_uqp_del{nullptr}, vptr_deleter_guard_flag{false},
rtti_uqp_del{nullptr}, vptr_is_using_noop_deleter{false}, vptr_is_using_builtin_delete{false},
vptr_deleter_guard_flag{false},
vptr_is_using_noop_deleter{false},
vptr_is_using_builtin_delete{false},
vptr_is_external_shared_ptr{false} {} vptr_is_external_shared_ptr{false} {}
bool has_pointee() const { return vptr.get() != nullptr; } bool has_pointee() const { return vptr.get() != nullptr; }
@ -88,59 +85,54 @@ struct smart_holder {
template <typename T> template <typename T>
void ensure_compatible_rtti_held(const char *context) const { void ensure_compatible_rtti_held(const char *context) const {
if (!rtti_held) { if (!rtti_held) {
throw std::runtime_error(std::string("Unpopulated holder (") + context + throw std::runtime_error(std::string("Unpopulated holder (") + context + ").");
").");
} }
const std::type_info *rtti_requested = &typeid(T); const std::type_info *rtti_requested = &typeid(T);
if (!(*rtti_requested == *rtti_held)) { if (!(*rtti_requested == *rtti_held)) {
throw std::runtime_error(std::string("Incompatible type (") + context + throw std::runtime_error(std::string("Incompatible type (") + context + ").");
").");
} }
} }
template <typename D> template <typename D>
void ensure_compatible_rtti_uqp_del(const char *context) const { void ensure_compatible_rtti_uqp_del(const char *context) const {
if (!rtti_uqp_del) { if (!rtti_uqp_del) {
throw std::runtime_error(std::string("Missing unique_ptr deleter (") + throw std::runtime_error(std::string("Missing unique_ptr deleter (") + context + ").");
context + ").");
} }
const std::type_info *rtti_requested = &typeid(D); const std::type_info *rtti_requested = &typeid(D);
if (!(*rtti_requested == *rtti_uqp_del)) { if (!(*rtti_requested == *rtti_uqp_del)) {
throw std::runtime_error( throw std::runtime_error(std::string("Incompatible unique_ptr deleter (") + context
std::string("Incompatible unique_ptr deleter (") + context + ")."); + ").");
} }
} }
void ensure_has_pointee(const char *context) const { void ensure_has_pointee(const char *context) const {
if (!has_pointee()) { if (!has_pointee()) {
throw std::runtime_error(std::string("Disowned holder (") + context + throw std::runtime_error(std::string("Disowned holder (") + context + ").");
").");
} }
} }
void ensure_vptr_is_using_builtin_delete(const char *context) const { void ensure_vptr_is_using_builtin_delete(const char *context) const {
if (vptr_is_external_shared_ptr) { if (vptr_is_external_shared_ptr) {
throw std::runtime_error( throw std::runtime_error(std::string("Cannot disown external shared_ptr (") + context
std::string("Cannot disown external shared_ptr (") + context + ")."); + ").");
} }
if (vptr_is_using_noop_deleter) { if (vptr_is_using_noop_deleter) {
throw std::runtime_error( throw std::runtime_error(std::string("Cannot disown non-owning holder (") + context
std::string("Cannot disown non-owning holder (") + context + ")."); + ").");
} }
if (!vptr_is_using_builtin_delete) { if (!vptr_is_using_builtin_delete) {
throw std::runtime_error(std::string("Cannot disown custom deleter (") + throw std::runtime_error(std::string("Cannot disown custom deleter (") + context
context + ")."); + ").");
} }
} }
void ensure_use_count_1(const char *context) const { void ensure_use_count_1(const char *context) const {
if (vptr.get() == nullptr) { if (vptr.get() == nullptr) {
throw std::runtime_error(std::string("Cannot disown nullptr (") + throw std::runtime_error(std::string("Cannot disown nullptr (") + context + ").");
context + ").");
} }
if (vptr.use_count() != 1) { if (vptr.use_count() != 1) {
throw std::runtime_error(std::string("Cannot disown use_count != 1 (") + throw std::runtime_error(std::string("Cannot disown use_count != 1 (") + context
context + ")."); + ").");
} }
} }
@ -149,8 +141,7 @@ struct smart_holder {
smart_holder hld; smart_holder hld;
hld.rtti_held = &typeid(T); hld.rtti_held = &typeid(T);
hld.vptr_is_using_noop_deleter = true; hld.vptr_is_using_noop_deleter = true;
hld.vptr.reset(raw_ptr, hld.vptr.reset(raw_ptr, guarded_builtin_delete<T>(&hld.vptr_deleter_guard_flag));
guarded_builtin_delete<T>(&hld.vptr_deleter_guard_flag));
return hld; return hld;
} }
@ -183,14 +174,12 @@ struct smart_holder {
hld.rtti_held = &typeid(T); hld.rtti_held = &typeid(T);
hld.vptr_deleter_guard_flag = true; hld.vptr_deleter_guard_flag = true;
hld.vptr_is_using_builtin_delete = true; hld.vptr_is_using_builtin_delete = true;
hld.vptr.reset(raw_ptr, hld.vptr.reset(raw_ptr, guarded_builtin_delete<T>(&hld.vptr_deleter_guard_flag));
guarded_builtin_delete<T>(&hld.vptr_deleter_guard_flag));
return hld; return hld;
} }
template <typename T> template <typename T>
T* as_raw_ptr_release_ownership( T *as_raw_ptr_release_ownership(const char *context = "as_raw_ptr_release_ownership") {
const char* context = "as_raw_ptr_release_ownership") {
ensure_compatible_rtti_held<T>(context); ensure_compatible_rtti_held<T>(context);
ensure_vptr_is_using_builtin_delete(context); ensure_vptr_is_using_builtin_delete(context);
ensure_use_count_1(context); ensure_use_count_1(context);
@ -206,8 +195,7 @@ struct smart_holder {
hld.rtti_held = &typeid(T); hld.rtti_held = &typeid(T);
hld.vptr_deleter_guard_flag = true; hld.vptr_deleter_guard_flag = true;
hld.vptr_is_using_builtin_delete = true; hld.vptr_is_using_builtin_delete = true;
hld.vptr.reset(unq_ptr.get(), hld.vptr.reset(unq_ptr.get(), guarded_builtin_delete<T>(&hld.vptr_deleter_guard_flag));
guarded_builtin_delete<T>(&hld.vptr_deleter_guard_flag));
unq_ptr.release(); unq_ptr.release();
return hld; return hld;
} }
@ -218,14 +206,12 @@ struct smart_holder {
} }
template <typename T, typename D> template <typename T, typename D>
static smart_holder from_unique_ptr_with_deleter( static smart_holder from_unique_ptr_with_deleter(std::unique_ptr<T, D> &&unq_ptr) {
std::unique_ptr<T, D>&& unq_ptr) {
smart_holder hld; smart_holder hld;
hld.rtti_held = &typeid(T); hld.rtti_held = &typeid(T);
hld.rtti_uqp_del = &typeid(D); hld.rtti_uqp_del = &typeid(D);
hld.vptr_deleter_guard_flag = true; hld.vptr_deleter_guard_flag = true;
hld.vptr.reset(unq_ptr.get(), hld.vptr.reset(unq_ptr.get(), guarded_custom_deleter<T, D>(&hld.vptr_deleter_guard_flag));
guarded_custom_deleter<T, D>(&hld.vptr_deleter_guard_flag));
unq_ptr.release(); unq_ptr.release();
return hld; return hld;
} }

View File

@ -51,8 +51,7 @@ TEST_CASE("from_raw_ptr_unowned+rvalue_ref", "[S]") {
TEST_CASE("from_raw_ptr_unowned+as_raw_ptr_release_ownership", "[E]") { TEST_CASE("from_raw_ptr_unowned+as_raw_ptr_release_ownership", "[E]") {
static int value = 19; static int value = 19;
auto hld = smart_holder::from_raw_ptr_unowned(&value); auto hld = smart_holder::from_raw_ptr_unowned(&value);
REQUIRE_THROWS_WITH( REQUIRE_THROWS_WITH(hld.as_raw_ptr_release_ownership<int>(),
hld.as_raw_ptr_release_ownership<int>(),
"Cannot disown non-owning holder (as_raw_ptr_release_ownership)."); "Cannot disown non-owning holder (as_raw_ptr_release_ownership).");
} }
@ -69,8 +68,7 @@ TEST_CASE("from_raw_ptr_unowned+as_unique_ptr_with_deleter", "[E]") {
auto condense_for_macro = [](smart_holder &hld) { auto condense_for_macro = [](smart_holder &hld) {
hld.as_unique_ptr_with_deleter<int, helpers::functor_builtin_delete<int>>(); hld.as_unique_ptr_with_deleter<int, helpers::functor_builtin_delete<int>>();
}; };
REQUIRE_THROWS_WITH( REQUIRE_THROWS_WITH(condense_for_macro(hld),
condense_for_macro(hld),
"Missing unique_ptr deleter (as_unique_ptr_with_deleter)."); "Missing unique_ptr deleter (as_unique_ptr_with_deleter).");
} }
@ -88,8 +86,7 @@ TEST_CASE("from_raw_ptr_take_ownership+lvalue_ref", "[S]") {
TEST_CASE("from_raw_ptr_take_ownership+as_raw_ptr_release_ownership1", "[S]") { 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 hld = smart_holder::from_raw_ptr_take_ownership(new int(19));
auto new_owner = auto new_owner = std::unique_ptr<int>(hld.as_raw_ptr_release_ownership<int>());
std::unique_ptr<int>(hld.as_raw_ptr_release_ownership<int>());
REQUIRE(!hld.has_pointee()); REQUIRE(!hld.has_pointee());
REQUIRE(*new_owner == 19); REQUIRE(*new_owner == 19);
} }
@ -97,8 +94,7 @@ 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]") { 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 hld = smart_holder::from_raw_ptr_take_ownership(new int(19));
auto shd_ptr = hld.as_shared_ptr<int>(); auto shd_ptr = hld.as_shared_ptr<int>();
REQUIRE_THROWS_WITH( REQUIRE_THROWS_WITH(hld.as_raw_ptr_release_ownership<int>(),
hld.as_raw_ptr_release_ownership<int>(),
"Cannot disown use_count != 1 (as_raw_ptr_release_ownership)."); "Cannot disown use_count != 1 (as_raw_ptr_release_ownership).");
} }
@ -112,8 +108,7 @@ TEST_CASE("from_raw_ptr_take_ownership+as_unique_ptr1", "[S]") {
TEST_CASE("from_raw_ptr_take_ownership+as_unique_ptr2", "[E]") { TEST_CASE("from_raw_ptr_take_ownership+as_unique_ptr2", "[E]") {
auto hld = smart_holder::from_raw_ptr_take_ownership(new int(19)); auto hld = smart_holder::from_raw_ptr_take_ownership(new int(19));
auto shd_ptr = hld.as_shared_ptr<int>(); auto shd_ptr = hld.as_shared_ptr<int>();
REQUIRE_THROWS_WITH(hld.as_unique_ptr<int>(), REQUIRE_THROWS_WITH(hld.as_unique_ptr<int>(), "Cannot disown use_count != 1 (as_unique_ptr).");
"Cannot disown use_count != 1 (as_unique_ptr).");
} }
TEST_CASE("from_raw_ptr_take_ownership+as_unique_ptr_with_deleter", "[E]") { TEST_CASE("from_raw_ptr_take_ownership+as_unique_ptr_with_deleter", "[E]") {
@ -121,8 +116,7 @@ TEST_CASE("from_raw_ptr_take_ownership+as_unique_ptr_with_deleter", "[E]") {
auto condense_for_macro = [](smart_holder &hld) { auto condense_for_macro = [](smart_holder &hld) {
hld.as_unique_ptr_with_deleter<int, helpers::functor_builtin_delete<int>>(); hld.as_unique_ptr_with_deleter<int, helpers::functor_builtin_delete<int>>();
}; };
REQUIRE_THROWS_WITH( REQUIRE_THROWS_WITH(condense_for_macro(hld),
condense_for_macro(hld),
"Missing unique_ptr deleter (as_unique_ptr_with_deleter)."); "Missing unique_ptr deleter (as_unique_ptr_with_deleter).");
} }
@ -144,8 +138,7 @@ TEST_CASE("from_unique_ptr+as_raw_ptr_release_ownership1", "[S]") {
std::unique_ptr<int> orig_owner(new int(19)); std::unique_ptr<int> orig_owner(new int(19));
auto hld = smart_holder::from_unique_ptr(std::move(orig_owner)); auto hld = smart_holder::from_unique_ptr(std::move(orig_owner));
REQUIRE(orig_owner.get() == nullptr); REQUIRE(orig_owner.get() == nullptr);
auto new_owner = auto new_owner = std::unique_ptr<int>(hld.as_raw_ptr_release_ownership<int>());
std::unique_ptr<int>(hld.as_raw_ptr_release_ownership<int>());
REQUIRE(!hld.has_pointee()); REQUIRE(!hld.has_pointee());
REQUIRE(*new_owner == 19); REQUIRE(*new_owner == 19);
} }
@ -155,8 +148,7 @@ TEST_CASE("from_unique_ptr+as_raw_ptr_release_ownership2", "[E]") {
auto hld = smart_holder::from_unique_ptr(std::move(orig_owner)); auto hld = smart_holder::from_unique_ptr(std::move(orig_owner));
REQUIRE(orig_owner.get() == nullptr); REQUIRE(orig_owner.get() == nullptr);
auto shd_ptr = hld.as_shared_ptr<int>(); auto shd_ptr = hld.as_shared_ptr<int>();
REQUIRE_THROWS_WITH( REQUIRE_THROWS_WITH(hld.as_raw_ptr_release_ownership<int>(),
hld.as_raw_ptr_release_ownership<int>(),
"Cannot disown use_count != 1 (as_raw_ptr_release_ownership)."); "Cannot disown use_count != 1 (as_raw_ptr_release_ownership).");
} }
@ -174,8 +166,7 @@ TEST_CASE("from_unique_ptr+as_unique_ptr2", "[E]") {
auto hld = smart_holder::from_unique_ptr(std::move(orig_owner)); auto hld = smart_holder::from_unique_ptr(std::move(orig_owner));
REQUIRE(orig_owner.get() == nullptr); REQUIRE(orig_owner.get() == nullptr);
auto shd_ptr = hld.as_shared_ptr<int>(); auto shd_ptr = hld.as_shared_ptr<int>();
REQUIRE_THROWS_WITH(hld.as_unique_ptr<int>(), REQUIRE_THROWS_WITH(hld.as_unique_ptr<int>(), "Cannot disown use_count != 1 (as_unique_ptr).");
"Cannot disown use_count != 1 (as_unique_ptr).");
} }
TEST_CASE("from_unique_ptr+as_unique_ptr_with_deleter", "[E]") { TEST_CASE("from_unique_ptr+as_unique_ptr_with_deleter", "[E]") {
@ -185,8 +176,7 @@ TEST_CASE("from_unique_ptr+as_unique_ptr_with_deleter", "[E]") {
auto condense_for_macro = [](smart_holder &hld) { auto condense_for_macro = [](smart_holder &hld) {
hld.as_unique_ptr_with_deleter<int, helpers::functor_builtin_delete<int>>(); hld.as_unique_ptr_with_deleter<int, helpers::functor_builtin_delete<int>>();
}; };
REQUIRE_THROWS_WITH( REQUIRE_THROWS_WITH(condense_for_macro(hld),
condense_for_macro(hld),
"Missing unique_ptr deleter (as_unique_ptr_with_deleter)."); "Missing unique_ptr deleter (as_unique_ptr_with_deleter).");
} }
@ -200,60 +190,50 @@ TEST_CASE("from_unique_ptr+as_shared_ptr", "[S]") {
} }
TEST_CASE("from_unique_ptr_with_deleter+lvalue_ref", "[S]") { TEST_CASE("from_unique_ptr_with_deleter+lvalue_ref", "[S]") {
std::unique_ptr<int, helpers::functor_builtin_delete<int>> orig_owner( std::unique_ptr<int, helpers::functor_builtin_delete<int>> orig_owner(new int(19));
new int(19));
auto hld = smart_holder::from_unique_ptr_with_deleter(std::move(orig_owner)); auto hld = smart_holder::from_unique_ptr_with_deleter(std::move(orig_owner));
REQUIRE(orig_owner.get() == nullptr); REQUIRE(orig_owner.get() == nullptr);
REQUIRE(hld.lvalue_ref<int>() == 19); REQUIRE(hld.lvalue_ref<int>() == 19);
} }
TEST_CASE("from_unique_ptr_with_deleter+as_raw_ptr_release_ownership", "[E]") { TEST_CASE("from_unique_ptr_with_deleter+as_raw_ptr_release_ownership", "[E]") {
std::unique_ptr<int, helpers::functor_builtin_delete<int>> orig_owner( std::unique_ptr<int, helpers::functor_builtin_delete<int>> orig_owner(new int(19));
new int(19));
auto hld = smart_holder::from_unique_ptr_with_deleter(std::move(orig_owner)); auto hld = smart_holder::from_unique_ptr_with_deleter(std::move(orig_owner));
REQUIRE(orig_owner.get() == nullptr); REQUIRE(orig_owner.get() == nullptr);
REQUIRE_THROWS_WITH( REQUIRE_THROWS_WITH(hld.as_raw_ptr_release_ownership<int>(),
hld.as_raw_ptr_release_ownership<int>(),
"Cannot disown custom deleter (as_raw_ptr_release_ownership)."); "Cannot disown custom deleter (as_raw_ptr_release_ownership).");
} }
TEST_CASE("from_unique_ptr_with_deleter+as_unique_ptr", "[E]") { TEST_CASE("from_unique_ptr_with_deleter+as_unique_ptr", "[E]") {
std::unique_ptr<int, helpers::functor_builtin_delete<int>> orig_owner( std::unique_ptr<int, helpers::functor_builtin_delete<int>> orig_owner(new int(19));
new int(19));
auto hld = smart_holder::from_unique_ptr_with_deleter(std::move(orig_owner)); auto hld = smart_holder::from_unique_ptr_with_deleter(std::move(orig_owner));
REQUIRE(orig_owner.get() == nullptr); REQUIRE(orig_owner.get() == nullptr);
REQUIRE_THROWS_WITH(hld.as_unique_ptr<int>(), REQUIRE_THROWS_WITH(hld.as_unique_ptr<int>(), "Cannot disown custom deleter (as_unique_ptr).");
"Cannot disown custom deleter (as_unique_ptr).");
} }
TEST_CASE("from_unique_ptr_with_deleter+as_unique_ptr_with_deleter1", "[S]") { TEST_CASE("from_unique_ptr_with_deleter+as_unique_ptr_with_deleter1", "[S]") {
std::unique_ptr<int, helpers::functor_builtin_delete<int>> orig_owner( std::unique_ptr<int, helpers::functor_builtin_delete<int>> orig_owner(new int(19));
new int(19));
auto hld = smart_holder::from_unique_ptr_with_deleter(std::move(orig_owner)); auto hld = smart_holder::from_unique_ptr_with_deleter(std::move(orig_owner));
REQUIRE(orig_owner.get() == nullptr); REQUIRE(orig_owner.get() == nullptr);
std::unique_ptr<int, helpers::functor_builtin_delete<int>> new_owner = std::unique_ptr<int, helpers::functor_builtin_delete<int>> new_owner
hld.as_unique_ptr_with_deleter<int, = hld.as_unique_ptr_with_deleter<int, helpers::functor_builtin_delete<int>>();
helpers::functor_builtin_delete<int>>();
REQUIRE(!hld.has_pointee()); REQUIRE(!hld.has_pointee());
REQUIRE(*new_owner == 19); REQUIRE(*new_owner == 19);
} }
TEST_CASE("from_unique_ptr_with_deleter+as_unique_ptr_with_deleter2", "[E]") { TEST_CASE("from_unique_ptr_with_deleter+as_unique_ptr_with_deleter2", "[E]") {
std::unique_ptr<int, helpers::functor_builtin_delete<int>> orig_owner( std::unique_ptr<int, helpers::functor_builtin_delete<int>> orig_owner(new int(19));
new int(19));
auto hld = smart_holder::from_unique_ptr_with_deleter(std::move(orig_owner)); auto hld = smart_holder::from_unique_ptr_with_deleter(std::move(orig_owner));
REQUIRE(orig_owner.get() == nullptr); REQUIRE(orig_owner.get() == nullptr);
auto condense_for_macro = [](smart_holder &hld) { auto condense_for_macro = [](smart_holder &hld) {
hld.as_unique_ptr_with_deleter<int, helpers::functor_other_delete<int>>(); hld.as_unique_ptr_with_deleter<int, helpers::functor_other_delete<int>>();
}; };
REQUIRE_THROWS_WITH( REQUIRE_THROWS_WITH(condense_for_macro(hld),
condense_for_macro(hld),
"Incompatible unique_ptr deleter (as_unique_ptr_with_deleter)."); "Incompatible unique_ptr deleter (as_unique_ptr_with_deleter).");
} }
TEST_CASE("from_unique_ptr_with_deleter+as_shared_ptr", "[S]") { TEST_CASE("from_unique_ptr_with_deleter+as_shared_ptr", "[S]") {
std::unique_ptr<int, helpers::functor_builtin_delete<int>> orig_owner( std::unique_ptr<int, helpers::functor_builtin_delete<int>> orig_owner(new int(19));
new int(19));
auto hld = smart_holder::from_unique_ptr_with_deleter(std::move(orig_owner)); auto hld = smart_holder::from_unique_ptr_with_deleter(std::move(orig_owner));
REQUIRE(orig_owner.get() == nullptr); REQUIRE(orig_owner.get() == nullptr);
std::shared_ptr<int> new_owner = hld.as_shared_ptr<int>(); std::shared_ptr<int> new_owner = hld.as_shared_ptr<int>();
@ -270,8 +250,7 @@ TEST_CASE("from_shared_ptr+lvalue_ref", "[S]") {
TEST_CASE("from_shared_ptr+as_raw_ptr_release_ownership", "[E]") { TEST_CASE("from_shared_ptr+as_raw_ptr_release_ownership", "[E]") {
std::shared_ptr<int> orig_owner(new int(19)); std::shared_ptr<int> orig_owner(new int(19));
auto hld = smart_holder::from_shared_ptr(orig_owner); auto hld = smart_holder::from_shared_ptr(orig_owner);
REQUIRE_THROWS_WITH( REQUIRE_THROWS_WITH(hld.as_raw_ptr_release_ownership<int>(),
hld.as_raw_ptr_release_ownership<int>(),
"Cannot disown external shared_ptr (as_raw_ptr_release_ownership)."); "Cannot disown external shared_ptr (as_raw_ptr_release_ownership).");
} }
@ -288,8 +267,7 @@ TEST_CASE("from_shared_ptr+as_unique_ptr_with_deleter", "[E]") {
auto condense_for_macro = [](smart_holder &hld) { auto condense_for_macro = [](smart_holder &hld) {
hld.as_unique_ptr_with_deleter<int, helpers::functor_builtin_delete<int>>(); hld.as_unique_ptr_with_deleter<int, helpers::functor_builtin_delete<int>>();
}; };
REQUIRE_THROWS_WITH( REQUIRE_THROWS_WITH(condense_for_macro(hld),
condense_for_macro(hld),
"Missing unique_ptr deleter (as_unique_ptr_with_deleter)."); "Missing unique_ptr deleter (as_unique_ptr_with_deleter).");
} }
@ -301,15 +279,13 @@ TEST_CASE("from_shared_ptr+as_shared_ptr", "[S]") {
TEST_CASE("error_unpopulated_holder", "[E]") { TEST_CASE("error_unpopulated_holder", "[E]") {
smart_holder hld; smart_holder hld;
REQUIRE_THROWS_WITH(hld.as_raw_ptr_unowned<int>(), REQUIRE_THROWS_WITH(hld.as_raw_ptr_unowned<int>(), "Unpopulated holder (as_raw_ptr_unowned).");
"Unpopulated holder (as_raw_ptr_unowned).");
} }
TEST_CASE("error_incompatible_type", "[E]") { TEST_CASE("error_incompatible_type", "[E]") {
static int value = 19; static int value = 19;
auto hld = smart_holder::from_raw_ptr_unowned(&value); auto hld = smart_holder::from_raw_ptr_unowned(&value);
REQUIRE_THROWS_WITH(hld.as_unique_ptr<std::string>(), REQUIRE_THROWS_WITH(hld.as_unique_ptr<std::string>(), "Incompatible type (as_unique_ptr).");
"Incompatible type (as_unique_ptr).");
} }
TEST_CASE("error_disowned_holder", "[E]") { TEST_CASE("error_disowned_holder", "[E]") {
@ -321,6 +297,5 @@ TEST_CASE("error_disowned_holder", "[E]") {
TEST_CASE("error_cannot_disown_nullptr", "[E]") { TEST_CASE("error_cannot_disown_nullptr", "[E]") {
auto hld = smart_holder::from_raw_ptr_take_ownership(new int(19)); auto hld = smart_holder::from_raw_ptr_take_ownership(new int(19));
hld.as_unique_ptr<int>(); hld.as_unique_ptr<int>();
REQUIRE_THROWS_WITH(hld.as_unique_ptr<int>(), REQUIRE_THROWS_WITH(hld.as_unique_ptr<int>(), "Cannot disown nullptr (as_unique_ptr).");
"Cannot disown nullptr (as_unique_ptr).");
} }