Fix bug #636 in optional emplace for pod types (#638)

This commit is contained in:
Chiraffollo 2022-11-23 10:25:24 +01:00 committed by GitHub
parent 3623ba5b38
commit 82c2f8a26d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 6 deletions

View File

@ -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;
}

View File

@ -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());
}
};
}