From bbee1ad262861deb0135dcfabfffa79ad6ad805d Mon Sep 17 00:00:00 2001 From: Nursan Valeyev Date: Tue, 12 Oct 2021 18:17:24 +0300 Subject: [PATCH 1/2] Add test for `emplace()` --- tests/emplace.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/emplace.cpp b/tests/emplace.cpp index 4edb319..051096d 100644 --- a/tests/emplace.cpp +++ b/tests/emplace.cpp @@ -11,3 +11,14 @@ TEST_CASE("Emplace", "[emplace]") { REQUIRE(i->second.first == 3); REQUIRE(i->second.second == 4); } + +struct A { + A() { + throw std::exception(); + } +}; + +TEST_CASE("Emplace with exception thrown", "[emplace]") { + tl::optional a; + REQUIRE_THROWS(a.emplace()); +} From 5d3e7d20d47c75edd28129e36da19aef059146e8 Mon Sep 17 00:00:00 2001 From: Nursan Valeyev Date: Tue, 12 Oct 2021 18:17:30 +0300 Subject: [PATCH 2/2] Remove `noexcept` specifier for `construct()` --- include/tl/optional.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/tl/optional.hpp b/include/tl/optional.hpp index 37b774a..ea06e9e 100644 --- a/include/tl/optional.hpp +++ b/include/tl/optional.hpp @@ -409,7 +409,7 @@ template struct optional_operations_base : optional_storage_base { this->m_has_value = false; } - template void construct(Args &&... args) noexcept { + template void construct(Args &&... args) { new (std::addressof(this->m_value)) T(std::forward(args)...); this->m_has_value = true; }