diff --git a/include/boost/optional/detail/optional_reference_spec.hpp b/include/boost/optional/detail/optional_reference_spec.hpp index 4471ab06..ecdbe7c0 100644 --- a/include/boost/optional/detail/optional_reference_spec.hpp +++ b/include/boost/optional/detail/optional_reference_spec.hpp @@ -172,9 +172,10 @@ class optional : public optional_detail::optional_tag constexpr T& value() const { - return this->is_initialized() ? - this->get() : - (boost::throw_exception(boost::bad_optional_access()), this->get()); + if (!this->is_initialized()) { + boost::throw_exception(boost::bad_optional_access()); + } + return this->get(); } constexpr explicit operator bool() const BOOST_NOEXCEPT { return ptr_ != 0; } diff --git a/include/boost/optional/detail/union_optional.hpp b/include/boost/optional/detail/union_optional.hpp index b735d5ab..c12e12fe 100644 --- a/include/boost/optional/detail/union_optional.hpp +++ b/include/boost/optional/detail/union_optional.hpp @@ -599,7 +599,10 @@ namespace boost { constexpr reference_const_type value() const& { - return this->is_initialized() ? this->get() : (boost::throw_exception(boost::bad_optional_access()), this->get()); + if (this->is_initialized()) + return this->get(); + else + boost::throw_exception(boost::bad_optional_access()); } BOOST_CXX14_CONSTEXPR reference_type value() &