Skip to content

Commit

Permalink
Merge branch 'pull-request/#858-fix-unique_ptr-assigning-nullptr-to-a…
Browse files Browse the repository at this point in the history
…-null-unique_ptr-causes-an-assert' into development
  • Loading branch information
John Wellbelove committed Mar 9, 2024
2 parents 9a520a3 + abb0494 commit 8593f95
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 8593f95

Please sign in to comment.