Skip to content

Commit

Permalink
fix(unique_ptr): assigning nullptr to a null unique_ptr causes an ass…
Browse files Browse the repository at this point in the history
…ert (#858)
  • Loading branch information
dsludwig authored Mar 9, 2024
1 parent a98d387 commit abb0494
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
10 changes: 8 additions & 2 deletions include/etl/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -1424,15 +1424,21 @@ namespace etl
//*********************************
unique_ptr& operator =(std::nullptr_t) ETL_NOEXCEPT
{
reset(nullptr);
if (p)
{
reset(nullptr);
}

return *this;
}
#else
//*********************************
unique_ptr& operator =(void*) ETL_NOEXCEPT
{
reset(NULL);
if (p)
{
reset(NULL);
}

return *this;
}
Expand Down
11 changes: 11 additions & 0 deletions test/test_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,17 @@ namespace
CHECK(!bool(up));
}

//*************************************************************************
TEST(test_unique_ptr_nullptr_from_nullptr_assignment)
{
etl::unique_ptr<int> up;

up = nullptr;

CHECK(up.get() == nullptr);
CHECK(!bool(up));
}

//*************************************************************************
TEST(test_unique_ptr_move_assignment)
{
Expand Down

0 comments on commit abb0494

Please sign in to comment.