diff --git a/tl/optional.hpp b/tl/optional.hpp index 395c58a..8212923 100644 --- a/tl/optional.hpp +++ b/tl/optional.hpp @@ -1190,7 +1190,9 @@ public: class U, detail::enable_from_other * = nullptr, detail::enable_if_t::value> * = nullptr> optional(const optional &rhs) { - this->construct(*rhs); + if (rhs.has_value()) { + this->construct(*rhs); + } } /// \exclude @@ -1198,7 +1200,9 @@ public: detail::enable_if_t::value> * = nullptr> explicit optional(const optional &rhs) { - this->construct(*rhs); + if (rhs.has_value()) { + this->construct(*rhs); + } } /// Converting move constructor. @@ -1207,7 +1211,9 @@ public: class U, detail::enable_from_other * = nullptr, detail::enable_if_t::value> * = nullptr> optional(optional &&rhs) { - this->construct(std::move(*rhs)); + if (rhs.has_value()) { + this->construct(std::move(*rhs)); + } } /// \exclude @@ -1215,7 +1221,9 @@ public: class U, detail::enable_from_other * = nullptr, detail::enable_if_t::value> * = nullptr> explicit optional(optional &&rhs) { - this->construct(std::move(*rhs)); + if (rhs.has_value()) { + this->construct(std::move(*rhs)); + } } /// Destroys the stored value if there is one.