Skip to content

Commit 8a6585a

Browse files
LWG-3548 shared_ptr construction from unique_ptr should move (not copy) the deleter (#2007)
Co-authored-by: Stephan T. Lavavej <[email protected]>
1 parent 853e64f commit 8a6585a

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

stl/inc/memory

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1642,7 +1642,8 @@ public:
16421642

16431643
if (_Fancy) {
16441644
const _Raw_t _Raw = _Fancy;
1645-
const auto _Rx = new _Ref_count_resource<_Fancy_t, _Deleter_t>(_Fancy, _Other.get_deleter());
1645+
const auto _Rx =
1646+
new _Ref_count_resource<_Fancy_t, _Deleter_t>(_Fancy, _STD forward<_Dx>(_Other.get_deleter()));
16461647
_Set_ptr_rep_and_enable_shared(_Raw, _Rx);
16471648
_Other.release();
16481649
}

tests/std/tests/Dev10_722102_shared_ptr_nullptr/test.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,14 @@ namespace unique_ptr_ {
211211
assert(*ptr.ptr_ == 42);
212212
*ptr.ptr_ = 13;
213213
}
214+
215+
// Also test LWG-3548 "shared_ptr construction from unique_ptr should move (not copy) the deleter".
216+
fancy_deleter() = default;
217+
fancy_deleter(fancy_deleter&&) = default;
218+
219+
fancy_deleter(const fancy_deleter&) = delete;
220+
fancy_deleter& operator=(fancy_deleter&&) = delete;
221+
fancy_deleter& operator=(const fancy_deleter&) = delete;
214222
};
215223

216224
template <class>

0 commit comments

Comments
 (0)