Skip to content

Commit 87a305e

Browse files
committed
Fixed deleter move assignment and construction
1 parent 4c60549 commit 87a305e

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

include/oup/observable_unique_ptr.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,17 @@ class observable_unique_ptr {
180180
explicit observable_unique_ptr(T* value, Deleter del) :
181181
observable_unique_ptr(allocate_block_(), value, std::move(del)) {}
182182

183+
/// Transfer ownership by implicit casting
184+
/** \param value The pointer to take ownership from
185+
* \note After this observable_unique_ptr is created, the source
186+
* pointer is set to null and looses ownership.
187+
*/
188+
observable_unique_ptr(observable_unique_ptr&& value) noexcept :
189+
observable_unique_ptr(value.block, value.pointer, std::move(value.deleter)) {
190+
value.block = nullptr;
191+
value.pointer = nullptr;
192+
}
193+
183194
/// Transfer ownership by implicit casting
184195
/** \param value The pointer to take ownership from
185196
* \note After this observable_unique_ptr is created, the source

tests/runtime_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ TEST_CASE("owner move constructor with deleter", "[owner_construction]") {
7171
REQUIRE(instances == 1);
7272
REQUIRE(instances_deleter == 2);
7373
REQUIRE(ptr.get() != nullptr);
74-
REQUIRE(ptr.get_deleter().state_ == 0);
74+
REQUIRE(ptr.get_deleter().state_ == 42);
7575
}
7676

7777
REQUIRE(instances == 0);
@@ -212,7 +212,7 @@ TEST_CASE("owner move assignment operator with deleter", "[owner_assignment]") {
212212
REQUIRE(instances == 1);
213213
REQUIRE(instances_deleter == 2);
214214
REQUIRE(ptr.get() != nullptr);
215-
REQUIRE(ptr.get_deleter().state_ == 0);
215+
REQUIRE(ptr.get_deleter().state_ == 42);
216216
}
217217

218218
REQUIRE(instances == 0);

0 commit comments

Comments
 (0)