From 17678211611839e9afd99488716167e602c1f4d7 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sun, 19 Feb 2023 16:48:35 -0600 Subject: [PATCH] [ox/std] Fix various issues with Optional copy and move constructors --- deps/ox/src/ox/std/optional.hpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/deps/ox/src/ox/std/optional.hpp b/deps/ox/src/ox/std/optional.hpp index 3110d5ab..fa8ed74b 100644 --- a/deps/ox/src/ox/std/optional.hpp +++ b/deps/ox/src/ox/std/optional.hpp @@ -32,16 +32,13 @@ class Optional { constexpr Optional(const Optional &other) { if (other.m_ptr) { - m_ptr = new(m_data.data()) T(*other.m_ptr); + m_ptr = std::construct_at(m_data.data(), *other.m_ptr); } } - constexpr Optional(const Optional &&other) noexcept { - if (m_ptr) { - m_ptr->~T(); - } + constexpr Optional(Optional &&other) noexcept { if (other.m_ptr) { - m_ptr = new(m_data.data()) T(std::move(*other.m_ptr)); + m_ptr = std::construct_at(m_data.data(), std::move(*other.m_ptr)); } } @@ -100,7 +97,7 @@ class Optional { emplace(); } *m_ptr = *other.m_ptr; - } else if (m_ptr) { + } else { reset(); } return *this; @@ -115,7 +112,7 @@ class Optional { emplace(); } *m_ptr = std::move(*other.m_ptr); - } else if (m_ptr) { + } else { reset(); } return *this; @@ -153,7 +150,7 @@ class Optional { return m_ptr; } - constexpr void reset() noexcept { + constexpr void reset() { if (std::is_constant_evaluated()) { ox::safeDelete(m_ptr); } else if (has_value()) {