From a1721a02db974ae3850461b573d8d337468f57d3 Mon Sep 17 00:00:00 2001 From: Tor Egge Date: Sun, 5 Mar 2023 14:30:49 +0100 Subject: Include memory to get declaration of std::addressof. --- vespalib/src/tests/ref_counted/ref_counted_test.cpp | 18 ++++++++++++++++-- vespalib/src/vespa/vespalib/util/ref_counted.h | 1 + 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/vespalib/src/tests/ref_counted/ref_counted_test.cpp b/vespalib/src/tests/ref_counted/ref_counted_test.cpp index 046823a9ebc..cba3b1cda90 100644 --- a/vespalib/src/tests/ref_counted/ref_counted_test.cpp +++ b/vespalib/src/tests/ref_counted/ref_counted_test.cpp @@ -34,6 +34,20 @@ struct Leaf : Base { std::atomic Leaf::ctor_cnt = 0; std::atomic Leaf::dtor_cnt = 0; +void copy_assign_ref_counted_leaf_real(ref_counted& lhs, const ref_counted &rhs) +{ + lhs = rhs; +} + +void (*copy_assign_ref_counted_leaf)(ref_counted& lhs, const ref_counted &rhs) = copy_assign_ref_counted_leaf_real; + +void move_assign_ref_counted_leaf_real(ref_counted& lhs, ref_counted&& rhs) +{ + lhs = rhs; +} + +void (*move_assign_ref_counted_leaf)(ref_counted& lhs, ref_counted&& rhs) = move_assign_ref_counted_leaf_real; + // check that the expected number of objects have been created and // destroyed while this object was in scope. struct CheckObjects { @@ -197,8 +211,8 @@ TEST(RefCountedTest, compile_errors_when_uncommented) { TEST(RefCountedTest, self_assign) { ref_counted ref = make_ref_counted(10); - ref = ref; - ref = std::move(ref); + copy_assign_ref_counted_leaf(ref, ref); + move_assign_ref_counted_leaf(ref, std::move(ref)); EXPECT_EQ(ref->count_refs(), 1); EXPECT_EQ(ref->val, 10); } diff --git a/vespalib/src/vespa/vespalib/util/ref_counted.h b/vespalib/src/vespa/vespalib/util/ref_counted.h index ab0e1c82044..0b75cc51d7a 100644 --- a/vespalib/src/vespa/vespalib/util/ref_counted.h +++ b/vespalib/src/vespa/vespalib/util/ref_counted.h @@ -4,6 +4,7 @@ #include #include +#include #include // This file contains code that implements intrusive reference -- cgit v1.2.3 From 72a7ea5cae8b38e502787671538ac419225876b0 Mon Sep 17 00:00:00 2001 From: Tor Egge Date: Sun, 5 Mar 2023 14:45:29 +0100 Subject: Use move assignment. --- vespalib/src/tests/ref_counted/ref_counted_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vespalib/src/tests/ref_counted/ref_counted_test.cpp b/vespalib/src/tests/ref_counted/ref_counted_test.cpp index cba3b1cda90..d831e664374 100644 --- a/vespalib/src/tests/ref_counted/ref_counted_test.cpp +++ b/vespalib/src/tests/ref_counted/ref_counted_test.cpp @@ -43,7 +43,7 @@ void (*copy_assign_ref_counted_leaf)(ref_counted& lhs, const ref_counted& lhs, ref_counted&& rhs) { - lhs = rhs; + lhs = std::move(rhs); } void (*move_assign_ref_counted_leaf)(ref_counted& lhs, ref_counted&& rhs) = move_assign_ref_counted_leaf_real; -- cgit v1.2.3