Skip to content
This repository was archived by the owner on Jan 29, 2026. It is now read-only.

Commit fdfc2cb

Browse files
authored
Fix swap for trivial proxy (#249)
1 parent 6670039 commit fdfc2cb

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

proxy.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ class proxy : public details::facade_traits<F>::direct_accessor {
903903
if constexpr (F::constraints.relocatability == constraint_level::trivial ||
904904
F::constraints.copyability == constraint_level::trivial) {
905905
std::swap(meta_, rhs.meta_);
906-
std::swap(ptr_, rhs.ptr);
906+
std::swap(ptr_, rhs.ptr_);
907907
} else {
908908
if (meta_.has_value()) {
909909
if (rhs.meta_.has_value()) {

tests/proxy_lifetime_tests.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,16 @@ TEST(ProxyLifetimeTests, TestSwap_Null_Null) {
974974
ASSERT_FALSE(p2.has_value());
975975
}
976976

977+
TEST(ProxyLifetimeTests, TestSwap_Trivial) {
978+
pro::proxy<details::TestTrivialFacade> p1 = pro::make_proxy<details::TestTrivialFacade>(123);
979+
pro::proxy<details::TestTrivialFacade> p2 = pro::make_proxy<details::TestTrivialFacade>(456);
980+
swap(p1, p2);
981+
ASSERT_TRUE(p1.has_value());
982+
ASSERT_EQ(ToString(*p1), "456");
983+
ASSERT_TRUE(p2.has_value());
984+
ASSERT_EQ(ToString(*p2), "123");
985+
}
986+
977987
TEST(ProxyLifetimeTests, Test_DirectConvension_Lvalue) {
978988
utils::LifetimeTracker tracker;
979989
std::vector<utils::LifetimeOperation> expected_ops;

0 commit comments

Comments
 (0)