diff --git a/include/etl/optional.h b/include/etl/optional.h index 7ab1d8c21..4707d55b2 100644 --- a/include/etl/optional.h +++ b/include/etl/optional.h @@ -764,12 +764,6 @@ namespace etl template ETL_CONSTEXPR14 void emplace(Args && ... args) { - if (valid) - { - // Destroy the old one. - storage.template get_reference().~T(); - } - storage = T(ETL_OR_STD::forward(args)...); valid = true; } diff --git a/test/test_optional.cpp b/test/test_optional.cpp index 44a91557e..03eee1d12 100644 --- a/test/test_optional.cpp +++ b/test/test_optional.cpp @@ -484,5 +484,15 @@ namespace CHECK_EQUAL(false, result.has_value()); } + + //************************************************************************* + TEST(test_optional_emplace_bug_636) + { + etl::optional result = 1; + result.emplace(2); + + CHECK_TRUE(result.has_value()); + CHECK_EQUAL(2, result.value()); + } }; }