Skip to content

Commit

Permalink
Fix bug #636 in optional emplace for pod types (#638)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chiraffollo authored Nov 23, 2022
1 parent 3623ba5 commit 82c2f8a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 0 additions & 6 deletions include/etl/optional.h
Original file line number Diff line number Diff line change
Expand Up @@ -764,12 +764,6 @@ namespace etl
template <typename ... Args>
ETL_CONSTEXPR14 void emplace(Args && ... args)
{
if (valid)
{
// Destroy the old one.
storage.template get_reference<T>().~T();
}

storage = T(ETL_OR_STD::forward<Args>(args)...);
valid = true;
}
Expand Down
10 changes: 10 additions & 0 deletions test/test_optional.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,5 +484,15 @@ namespace

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

//*************************************************************************
TEST(test_optional_emplace_bug_636)
{
etl::optional<std::uint8_t> result = 1;
result.emplace(2);

CHECK_TRUE(result.has_value());
CHECK_EQUAL(2, result.value());
}
};
}

0 comments on commit 82c2f8a

Please sign in to comment.