diff --git a/docs/spec/proxy/assignment.md b/docs/spec/proxy/assignment.md index 40e13fb..370be5a 100644 --- a/docs/spec/proxy/assignment.md +++ b/docs/spec/proxy/assignment.md @@ -50,14 +50,14 @@ proxy& operator=(P&& ptr) F::destructibility >= lifetime_requirement::supported); ``` -Assigns a new value to `proxy` or destroys the contained value. +Assigns a new value to `proxy` or destroys the contained value. For `(2-6)`, the source of the assignment may be owned by the contained value of `*this`, such as in `p = std::move(p->next)`. Therefore, if `*this` contains a value, the new value is first constructed from the source as a temporary `temp`, then the contained value is destroyed, and then the contained value is initialized from `temp` as specified below. If an exception is thrown while the new value is constructed from the source, `*this` is not modified. If an exception is thrown otherwise, `*this` does not contain a value. -- `(1)` Destroys the current contained value if it exists. After the call, `*this` does not contain a value. -- `(2)` Copy assignment operator copies the contained value of `rhs` to `*this`. If `rhs` does not contain a value, it destroys the contained value of `*this` (if any). When `F::copyability == lifetime_requirement::trivial`, copy assignment is defaulted. It is trivial only if the metadata storage and accessor base classes also permit trivial copy assignment. -- `(3)` Move assignment operator moves the contained value of `rhs` to `*this`. If `rhs` does not contain a value, it destroys the contained value of `*this` (if any). If the move construction throws when `F::relocatability == lifetime_requirement::supported`, `*this` does not contain a value. After move assignment, `rhs` is in a valid state with an unspecified value. The move assignment operator does not participate in overload resolution when `F::copyability == lifetime_requirement::trivial`, falling back to the defaulted copy assignment operator. -- `(4)` Converting copy assignment operator copies the contained value of `rhs` to `*this`, as if by constructing a `proxy` from `rhs` and assigning it. If `rhs` does not contain a value, it destroys the contained value of `*this` (if any). Participates in overload resolution only if `F2` is not `F` and `F` is a super of `F2`, reachable via `typename F2::super_types` transitively. -- `(5)` Converting move assignment operator moves the contained value of `rhs` to `*this`. If `rhs` does not contain a value, it destroys the contained value of `*this` (if any). If the move construction throws when `F::relocatability == lifetime_requirement::supported`, `*this` does not contain a value. After the assignment, `rhs` does not contain a value. Participates in overload resolution only if `F2` is not `F` and `F` is a super of `F2`, reachable via `typename F2::super_types` transitively. The converting move assignment operator does not participate in overload resolution when `F::copyability == lifetime_requirement::trivial`, falling back to `(4)`. -- `(6)` Let `VP` be `std::decay_t

`. Sets the contained value to an object of type `VP`, direct-non-list-initialized with `std::forward

(ptr)`. Participates in overload resolution only if `VP` is not a specialization of `proxy` and is a pointer-like type eligible for `proxy` (see [*ProxyFacade* requirements](../ProxyFacade.md)). *Since 3.3.0*: If [`proxiable`](../proxiable.md) is `false`, the program is ill-formed and a diagnostic is generated. +- `(1)` Destroys the current contained value if it exists. After the call, `*this` does not contain a value, even if the destruction throws. +- `(2)` Copy assignment operator copies the contained value of `rhs` to `*this`. If `rhs` does not contain a value, it destroys the contained value of `*this` (if any). If `*this` contains a value, `temp` is a `proxy`, and the contained value is initialized as if by `proxy(std::move(temp))` if `std::is_nothrow_move_constructible_v` is `true` or `std::is_nothrow_copy_constructible_v` is `false`, or as if by `proxy(std::as_const(temp))` otherwise. When `F::copyability == lifetime_requirement::trivial`, copy assignment is defaulted. It is trivial only if the metadata storage and accessor base classes also permit trivial copy assignment. +- `(3)` Move assignment operator moves the contained value of `rhs` to `*this`. If `rhs` does not contain a value, it destroys the contained value of `*this` (if any). If `*this` contains a value, `temp` is a `proxy`, and the contained value is initialized as if by `proxy(std::move(temp))`. If moving the contained value of `rhs` throws, `rhs` does not contain a value. After move assignment, `rhs` is in a valid state with an unspecified value. The move assignment operator does not participate in overload resolution when `F::copyability == lifetime_requirement::trivial`, falling back to the defaulted copy assignment operator. +- `(4)` Converting copy assignment operator copies the contained value of `rhs` to `*this`. If `rhs` does not contain a value, it destroys the contained value of `*this` (if any). If `*this` contains a value, `temp` is a `proxy`, and the contained value is initialized from it as in `(2)`. Participates in overload resolution only if `F2` is not `F` and `F` is a super of `F2`, reachable via `typename F2::super_types` transitively. +- `(5)` Converting move assignment operator moves the contained value of `rhs` to `*this`. If `rhs` does not contain a value, it destroys the contained value of `*this` (if any). If `*this` contains a value, `temp` is a `proxy`, and the contained value is initialized from it as in `(3)`. After the assignment, `rhs` does not contain a value, even if an exception is thrown. Participates in overload resolution only if `F2` is not `F` and `F` is a super of `F2`, reachable via `typename F2::super_types` transitively. The converting move assignment operator does not participate in overload resolution when `F::copyability == lifetime_requirement::trivial`, falling back to `(4)`. +- `(6)` Let `VP` be `std::decay_t

`. Sets the contained value to an object of type `VP`, direct-non-list-initialized with `std::forward

(ptr)`. If `*this` contains a value, `temp` is an object of type `VP`, and the contained value is direct-non-list-initialized with `std::move(temp)` if `std::is_move_constructible_v` is `true` and either `std::is_nothrow_move_constructible_v` is `true` or `std::is_nothrow_copy_constructible_v` is `false`, or with `std::as_const(temp)` otherwise. Participates in overload resolution only if `VP` is not a specialization of `proxy` and is a pointer-like type eligible for `proxy` (see [*ProxyFacade* requirements](../ProxyFacade.md)). *Since 3.3.0*: If [`proxiable`](../proxiable.md) is `false`, the program is ill-formed and a diagnostic is generated. ## Return Value diff --git a/include/proxy/v5/detail/core.h b/include/proxy/v5/detail/core.h index 910dae4..cdf7e42 100644 --- a/include/proxy/v5/detail/core.h +++ b/include/proxy/v5/detail/core.h @@ -204,6 +204,12 @@ template concept nothrow_constructible = constructible && noexcept(::new (std::declval()) T(std::declval()...)); +template +using move_or_copy_t = + std::conditional_t && + (std::is_nothrow_move_constructible_v || + !std::is_nothrow_copy_constructible_v), + T&&, const T&>; template struct copyability_traits : inapplicable_traits {}; @@ -1255,14 +1261,11 @@ class proxy : public detail::proxy_traits::direct_accessor, F::destructibility >= lifetime_requirement::supported) { if (this != std::addressof(rhs)) [[likely]] { - if constexpr (F::copyability == lifetime_requirement::nothrow) { - destroy(); - initialize(rhs); - } else if constexpr (F::relocatability >= - lifetime_requirement::supported) { - *this = proxy{rhs}; - } else { + if (meta_) { + proxy temp = rhs; reset(); + initialize(static_cast>(temp)); + } else { initialize(rhs); } } @@ -1277,8 +1280,13 @@ class proxy : public detail::proxy_traits::direct_accessor, F::copyability != lifetime_requirement::trivial) { if (this != std::addressof(rhs)) [[likely]] { - reset(); - initialize(std::move(rhs)); + if (meta_) { + proxy temp = std::move(rhs); + reset(); + initialize(std::move(temp)); + } else { + initialize(std::move(rhs)); + } } return *this; } @@ -1292,13 +1300,11 @@ class proxy : public detail::proxy_traits::direct_accessor, F::copyability >= lifetime_requirement::supported && F::destructibility >= lifetime_requirement::supported) { - if constexpr (F::copyability >= lifetime_requirement::nothrow) { - destroy(); - initialize(rhs); - } else if constexpr (F::relocatability >= lifetime_requirement::supported) { - *this = proxy{rhs}; - } else { + if (meta_) { + proxy temp = rhs; reset(); + initialize(static_cast>(temp)); + } else { initialize(rhs); } return *this; @@ -1314,8 +1320,13 @@ class proxy : public detail::proxy_traits::direct_accessor, F::destructibility >= lifetime_requirement::supported && F::copyability != lifetime_requirement::trivial) { - reset(); - initialize(std::move(rhs)); + if (meta_) { + proxy temp = std::move(rhs); + reset(); + initialize(std::move(temp)); + } else { + initialize(std::move(rhs)); + } return *this; } template @@ -1327,15 +1338,13 @@ class proxy : public detail::proxy_traits::direct_accessor, std::is_constructible_v, P> && F::destructibility >= lifetime_requirement::supported) { - if constexpr (std::is_nothrow_constructible_v, P>) { - destroy(); - initialize>(std::forward

(ptr)); - } else if constexpr (F::relocatability >= lifetime_requirement::supported || - F::copyability >= lifetime_requirement::nothrow) { - *this = proxy{std::forward

(ptr)}; - } else { + using VP = std::decay_t

; + if (meta_) { + VP temp(std::forward

(ptr)); reset(); - initialize>(std::forward

(ptr)); + initialize(static_cast>(temp)); + } else { + initialize(std::forward

(ptr)); } return *this; } @@ -1410,14 +1419,16 @@ class proxy : public detail::proxy_traits::direct_accessor, if (meta_) { if (rhs.meta_) { proxy temp = *this; - *this = rhs; - rhs = temp; + reset(); + initialize(rhs); + rhs.reset(); + rhs.initialize(temp); } else { - rhs = *this; + rhs.initialize(*this); reset(); } } else if (rhs.meta_) { - *this = rhs; + initialize(rhs); rhs.reset(); } } @@ -1501,7 +1512,10 @@ class proxy : public detail::proxy_traits::direct_accessor, } } template - void initialize(proxy&& rhs) { + void initialize(proxy&& rhs) + requires(F::relocatability >= lifetime_requirement::supported && + F::copyability != lifetime_requirement::trivial) + { PRO5D_DEBUG(std::ignore = &pro_symbol_guard;) if (rhs.has_value()) { detail::proxy_helper::meta_resetting_guard guard{rhs}; diff --git a/tests/proxy_lifetime_tests.cpp b/tests/proxy_lifetime_tests.cpp index cf02f88..621fa58 100644 --- a/tests/proxy_lifetime_tests.cpp +++ b/tests/proxy_lifetime_tests.cpp @@ -6,9 +6,13 @@ #include #include #include +#include #include #include +#include #include +#include +#include namespace proxy_lifetime_tests_detail { @@ -53,6 +57,8 @@ static_assert(!std::is_convertible_v, static_assert(!std::is_convertible_v, pro::proxy>); +static_assert(std::is_nothrow_assignable_v&, int*>); + struct TestNonDestructibleFacade : pro::facade_builder // ::add_convention // @@ -148,6 +154,74 @@ struct TestNonDestructibleCopyFacade ::support_destruction // ::build {}; +struct TestOwningCopyFacade + : pro::facade_builder // + ::add_convention // + ::support_copy // + ::support_relocation // + ::build {}; + +struct TestOwningDerivedFacade : pro::facade_builder // + ::add_facade // + ::build {}; + +enum class AssignmentEvent { kSourceUsed, kOwnerDestroyed }; + +const std::vector kSourceUsedBeforeOwnerDestroyed{ + AssignmentEvent::kSourceUsed, AssignmentEvent::kOwnerDestroyed}; + +struct AssignmentOrder { + const void* source = nullptr; + std::vector events; +}; + +template +class OrderedPtr { +public: + using element_type = int; + + OrderedPtr(int* value, AssignmentOrder* order) noexcept + : value_(value), order_(order) { + order_->source = this; + } + OrderedPtr(const OrderedPtr& rhs) noexcept + : value_(rhs.value_), order_(rhs.order_) { + rhs.Use(); + } + OrderedPtr(OrderedPtr&& rhs) noexcept + requires(Movable) + : value_(rhs.value_), order_(rhs.order_) { + rhs.Use(); + } + OrderedPtr(OrderedPtr&&) + requires(!Movable) + = delete; + int& operator*() const noexcept { return *value_; } + +private: + void Use() const noexcept { + if (order_->source == this) { + order_->events.push_back(AssignmentEvent::kSourceUsed); + } + } + + int* value_; + AssignmentOrder* order_; +}; + +template +struct OrderedOwner { + template + explicit OrderedOwner(AssignmentOrder* order, Args&&... args) + : order(order), member(std::forward(args)...) {} + ~OrderedOwner() { order->events.push_back(AssignmentEvent::kOwnerDestroyed); } + + friend std::string to_string(const OrderedOwner&) { return "owner"; } + + AssignmentOrder* order; + T member; +}; + } // namespace proxy_lifetime_tests_detail namespace detail = proxy_lifetime_tests_detail; @@ -515,18 +589,15 @@ TEST(ProxyLifetimeTests, TestPolyAssignment_FromValue_ToNull) { pro::proxy p; p = utils::LifetimeTracker::Session{&tracker}; ASSERT_TRUE(p.has_value()); - ASSERT_EQ(ToString(*p), "Session 3"); + ASSERT_EQ(ToString(*p), "Session 2"); expected_ops.emplace_back(1, utils::LifetimeOperationType::kValueConstruction); expected_ops.emplace_back(2, utils::LifetimeOperationType::kMoveConstruction); - expected_ops.emplace_back(3, - utils::LifetimeOperationType::kMoveConstruction); - expected_ops.emplace_back(2, utils::LifetimeOperationType::kDestruction); expected_ops.emplace_back(1, utils::LifetimeOperationType::kDestruction); ASSERT_TRUE(tracker.GetOperations() == expected_ops); } - expected_ops.emplace_back(3, utils::LifetimeOperationType::kDestruction); + expected_ops.emplace_back(2, utils::LifetimeOperationType::kDestruction); ASSERT_TRUE(tracker.GetOperations() == expected_ops); } @@ -843,18 +914,15 @@ TEST(ProxyLifetimeTests, TestCopyAssignment_FromValue_ToNull) { utils::LifetimeOperationType::kValueConstruction); p1 = p2; ASSERT_TRUE(p1.has_value()); - ASSERT_EQ(ToString(*p1), "Session 3"); + ASSERT_EQ(ToString(*p1), "Session 2"); ASSERT_TRUE(p2.has_value()); ASSERT_EQ(ToString(*p2), "Session 1"); expected_ops.emplace_back(2, utils::LifetimeOperationType::kCopyConstruction); - expected_ops.emplace_back(3, - utils::LifetimeOperationType::kMoveConstruction); - expected_ops.emplace_back(2, utils::LifetimeOperationType::kDestruction); ASSERT_TRUE(tracker.GetOperations() == expected_ops); } expected_ops.emplace_back(1, utils::LifetimeOperationType::kDestruction); - expected_ops.emplace_back(3, utils::LifetimeOperationType::kDestruction); + expected_ops.emplace_back(2, utils::LifetimeOperationType::kDestruction); ASSERT_TRUE(tracker.GetOperations() == expected_ops); } @@ -936,15 +1004,18 @@ TEST(ProxyLifetimeTests, TestMoveAssignment_FromValue_ToValue) { utils::LifetimeOperationType::kValueConstruction); p1 = std::move(p2); ASSERT_TRUE(p1.has_value()); - ASSERT_EQ(ToString(*p1), "Session 3"); + ASSERT_EQ(ToString(*p1), "Session 4"); ASSERT_FALSE(p2.has_value()); - expected_ops.emplace_back(1, utils::LifetimeOperationType::kDestruction); expected_ops.emplace_back(3, utils::LifetimeOperationType::kMoveConstruction); expected_ops.emplace_back(2, utils::LifetimeOperationType::kDestruction); + expected_ops.emplace_back(1, utils::LifetimeOperationType::kDestruction); + expected_ops.emplace_back(4, + utils::LifetimeOperationType::kMoveConstruction); + expected_ops.emplace_back(3, utils::LifetimeOperationType::kDestruction); ASSERT_TRUE(tracker.GetOperations() == expected_ops); } - expected_ops.emplace_back(3, utils::LifetimeOperationType::kDestruction); + expected_ops.emplace_back(4, utils::LifetimeOperationType::kDestruction); ASSERT_TRUE(tracker.GetOperations() == expected_ops); } @@ -969,12 +1040,13 @@ TEST(ProxyLifetimeTests, TestMoveAssignment_FromValue_ToValue_Exception) { ASSERT_EQ(e.type_, utils::LifetimeOperationType::kMoveConstruction); } ASSERT_TRUE(exception_thrown); - ASSERT_FALSE(p1.has_value()); + ASSERT_TRUE(p1.has_value()); + ASSERT_EQ(ToString(*p1), "Session 1"); ASSERT_FALSE(p2.has_value()); - expected_ops.emplace_back(1, utils::LifetimeOperationType::kDestruction); expected_ops.emplace_back(2, utils::LifetimeOperationType::kDestruction); ASSERT_TRUE(tracker.GetOperations() == expected_ops); } + expected_ops.emplace_back(1, utils::LifetimeOperationType::kDestruction); ASSERT_TRUE(tracker.GetOperations() == expected_ops); } @@ -1316,6 +1388,41 @@ TEST(ProxyLifetimeTests, Test_CopyAssignment_NoRelocation) { ASSERT_EQ(ToString(*p1), "111"); } +TEST(ProxyLifetimeTests, Test_CopyAssignment_NoRelocation_NothrowCopy) { + struct Pinned : pro::facade_builder // + ::add_convention // + ::support_copy // + ::support_relocation // + ::build {}; + int v1 = 111, v2 = 222; + pro::proxy p1 = &v1; + pro::proxy p2 = &v2; + static_assert(noexcept(p1 = p2)); + p1 = p2; + ASSERT_EQ(ToString(*p1), "222"); + ASSERT_EQ(ToString(*p2), "222"); +} + +TEST(ProxyLifetimeTests, Test_CopyAssignment_ThrowingRelocation_NothrowCopy) { + struct ThrowingRelocation + : pro::facade_builder // + ::add_convention // + ::support_copy // + ::support_relocation // + ::build {}; + int v1 = 111, v2 = 222; + pro::proxy p1{ + std::in_place_type>, &v1}; + pro::proxy p2{ + std::in_place_type>, &v2}; + static_assert(noexcept(p1 = p2)); + p1 = p2; + ASSERT_EQ(ToString(*p1), "222"); + ASSERT_EQ(ToString(*p2), "222"); +} + TEST(ProxyLifetimeTests, Test_PointerAssignment_NoRelocationNoCopy) { struct Pinned : pro::facade_builder // ::add_convention // + ::support_relocation // + ::build {}; + int v1 = 111, v2 = 222; + pro::proxy p{ + std::in_place_type>, &v1}; + utils::ThrowOnMovePtr ptr{&v2}; + static_assert(noexcept(p = ptr)); + p = ptr; + ASSERT_EQ(ToString(*p), "222"); +} + TEST(ProxyLifetimeTests, TestSwap_NoRelocation) { struct Pinned : pro::facade_builder // ::add_convention p2{ std::in_place_type, &tracker}; p1 = p2; - ASSERT_EQ(ToString(*p1), "Session 3"); + ASSERT_EQ(ToString(*p1), "Session 4"); ASSERT_TRUE(p2.has_value()); ASSERT_EQ(ToString(*p2), "Session 2"); } +TEST(ProxyLifetimeTests, + Test_ConvertingCopyAssignment_NoRelocation_NothrowCopy) { + struct Pinned : pro::facade_builder // + ::add_convention // + ::support_copy // + ::support_relocation // + ::build {}; + struct PinnedDerived : pro::facade_builder // + ::add_facade // + ::build {}; + int v1 = 111, v2 = 222; + pro::proxy p1 = &v1; + pro::proxy p2 = &v2; + static_assert(noexcept(p1 = p2)); + p1 = p2; + ASSERT_EQ(ToString(*p1), "222"); + ASSERT_EQ(ToString(*p2), "222"); +} + +TEST(ProxyLifetimeTests, + Test_ConvertingCopyAssignment_ThrowingRelocation_NothrowCopy) { + struct ThrowingRelocation + : pro::facade_builder // + ::add_convention // + ::support_copy // + ::support_relocation // + ::build {}; + struct ThrowingRelocationDerived : pro::facade_builder // + ::add_facade // + ::build {}; + int v1 = 111, v2 = 222; + pro::proxy p1{ + std::in_place_type>, &v1}; + pro::proxy p2{ + std::in_place_type>, &v2}; + static_assert(noexcept(p1 = p2)); + p1 = p2; + ASSERT_EQ(ToString(*p1), "222"); + ASSERT_EQ(ToString(*p2), "222"); +} + +TEST(ProxyLifetimeTests, + Test_ConvertingCopyAssignment_ThrowingRelocation_TrivialCopy) { + struct TrivialCopy + : pro::facade_builder // + ::add_convention // + ::support_copy // + ::support_relocation // + ::build {}; + struct TrivialCopyDerived : pro::facade_builder // + ::add_facade // + ::build {}; + int v1 = 111, v2 = 222; + pro::proxy p1{std::in_place_type>, + &v1}; + pro::proxy p2{ + std::in_place_type>, &v2}; + static_assert(noexcept(p1 = p2)); + p1 = p2; + ASSERT_EQ(ToString(*p1), "222"); + ASSERT_EQ(ToString(*p2), "222"); +} + TEST(ProxyLifetimeTests, Test_NonDestructible_Construction) { using Proxy = pro::proxy; alignas(Proxy) std::byte null_storage[sizeof(Proxy)]; @@ -1710,6 +1899,112 @@ TEST(ProxyLifetimeTests, Test_NonDestructible_NonDestructiblePtr) { ASSERT_EQ(ToString(**p2), "123"); } +TEST(ProxyLifetimeTests, TestCopyAssignment_FromOwnedValue) { + using F = detail::TestOwningCopyFacade; + detail::AssignmentOrder order; + int v = 7; + auto owner = std::make_shared>>( + &order, std::in_place_type>, &v, &order); + pro::proxy& source = owner->member; + pro::proxy target = std::move(owner); + target = source; + ASSERT_EQ(ToString(*target), "7"); + ASSERT_EQ(order.events, detail::kSourceUsedBeforeOwnerDestroyed); +} + +TEST(ProxyLifetimeTests, TestCopyAssignment_FromOwnedValue_NoRelocation) { + struct F : pro::facade_builder // + ::add_convention // + ::support_copy // + ::support_relocation // + ::build {}; + detail::AssignmentOrder order; + int v = 7; + auto owner = std::make_shared>>( + &order, std::in_place_type>, &v, &order); + pro::proxy& source = owner->member; + pro::proxy target = std::move(owner); + target = source; + ASSERT_EQ(ToString(*target), "7"); + ASSERT_EQ(order.events, detail::kSourceUsedBeforeOwnerDestroyed); +} + +TEST(ProxyLifetimeTests, TestMoveAssignment_FromOwnedValue) { + using F = detail::TestOwningCopyFacade; + detail::AssignmentOrder order; + int v = 7; + auto owner = std::make_shared>>( + &order, std::in_place_type>, &v, &order); + pro::proxy& source = owner->member; + pro::proxy target = std::move(owner); + target = std::move(source); + ASSERT_EQ(ToString(*target), "7"); + ASSERT_EQ(order.events, detail::kSourceUsedBeforeOwnerDestroyed); +} + +TEST(ProxyLifetimeTests, Test_ConvertingCopyAssignment_FromOwnedValue) { + using F = detail::TestOwningCopyFacade; + using F2 = detail::TestOwningDerivedFacade; + detail::AssignmentOrder order; + int v = 7; + auto owner = std::make_shared>>( + &order, std::in_place_type>, &v, &order); + pro::proxy& source = owner->member; + pro::proxy target = std::move(owner); + target = source; + ASSERT_EQ(ToString(*target), "7"); + ASSERT_EQ(order.events, detail::kSourceUsedBeforeOwnerDestroyed); +} + +TEST(ProxyLifetimeTests, Test_ConvertingMoveAssignment_FromOwnedValue) { + using F = detail::TestOwningCopyFacade; + using F2 = detail::TestOwningDerivedFacade; + detail::AssignmentOrder order; + int v = 7; + auto owner = std::make_shared>>( + &order, std::in_place_type>, &v, &order); + pro::proxy& source = owner->member; + pro::proxy target = std::move(owner); + target = std::move(source); + ASSERT_EQ(ToString(*target), "7"); + ASSERT_EQ(order.events, detail::kSourceUsedBeforeOwnerDestroyed); +} + +TEST(ProxyLifetimeTests, TestPolyAssignment_FromOwnedValue) { + struct F : pro::facade_builder // + ::add_convention // + ::add_skill // + ::restrict_layout<4 * sizeof(void*)> // + ::support_relocation // + ::build {}; + using Owner = detail::OrderedOwner>; + detail::AssignmentOrder order; + int v = 7; + auto target = pro::make_proxy_inplace(&order, &v, &order); + detail::OrderedPtr& source = proxy_cast(*target).member; + target = std::move(source); + ASSERT_EQ(ToString(*target), "7"); + ASSERT_EQ(order.events, detail::kSourceUsedBeforeOwnerDestroyed); +} + +TEST(ProxyLifetimeTests, TestPolyAssignment_FromOwnedValue_NonMovablePtr) { + struct F : pro::facade_builder // + ::add_convention // + ::support_relocation // + ::build {}; + detail::AssignmentOrder order; + int v = 7; + auto owner = + std::make_shared>>( + &order, &v, &order); + detail::OrderedPtr& source = owner->member; + pro::proxy target = std::move(owner); + static_assert(noexcept(target = source)); + target = source; + ASSERT_EQ(ToString(*target), "7"); + ASSERT_EQ(order.events, detail::kSourceUsedBeforeOwnerDestroyed); +} + TEST(ProxyLifetimeTests, Test_Substitution_TrivialDerived) { struct Super : pro::facade_builder // ::add_convention