Skip to content

Commit

Permalink
optional::operator=(nullopt_t) sets valid to false (#715)
Browse files Browse the repository at this point in the history
* optional::operator=(nullopt_t) sets valid to false

Fixes #714

* Add test case for #714
  • Loading branch information
musteresel committed Jun 17, 2023
1 parent f55fb92 commit 96092d8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/etl/optional.h
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,7 @@ namespace etl
//***************************************************************************
ETL_CONSTEXPR14 optional& operator =(etl::nullopt_t)
{
valid = false;
return *this;
}

Expand Down
9 changes: 9 additions & 0 deletions test/test_optional.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,15 @@ namespace
CHECK_TRUE(result.has_value());
CHECK_EQUAL(2, result.value());
}

//*************************************************************************
TEST(test_optional_pod_assign_bug_714)
{
etl::optional<int> o = 42;
o = etl::nullopt;

CHECK_EQUAL(false, o.has_value());
}
};
}

Expand Down

0 comments on commit 96092d8

Please sign in to comment.