Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions stl/inc/memory
Original file line number Diff line number Diff line change
Expand Up @@ -4244,10 +4244,10 @@ public:
~inout_ptr_t() {
if constexpr (!is_pointer_v<_SmartPtr>) {
_Smart_ptr.release();
}

if (!_Get_ptr()) {
return;
if (!_Get_ptr()) {
return;
}
}

_STD apply(
Expand Down
13 changes: 13 additions & 0 deletions tests/std/tests/P1132R7_out_ptr/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ void test_raw_ptr() {

assert(*int_ptr == 15);
}
// LWG-3897 inout_ptr will not update raw pointer to null
{
const auto delete_nullify = [](int** ptr) {
delete *ptr;
*ptr = nullptr;
};

int* ptr_allocated = new int{};

delete_nullify(inout_ptr(ptr_allocated));

assert(ptr_allocated == nullptr);
}
}

void test_shared_ptr() {
Expand Down