From 147be906358d74c437903cfa6bb74c1016fada1d Mon Sep 17 00:00:00 2001 From: Leander Schulten Date: Wed, 12 Aug 2026 15:45:03 +0200 Subject: [PATCH 1/2] Fix msvc warning unreachable code This restores the previous implementation and uses the same implementation as the other value functions. --- include/boost/optional/detail/union_optional.hpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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() & From 9700f084dd4c7f516a7a072f6944867061a7e036 Mon Sep 17 00:00:00 2001 From: Leander Schulten Date: Wed, 12 Aug 2026 16:23:05 +0200 Subject: [PATCH 2/2] Fix msvc warning unreachable code --- include/boost/optional/detail/optional_reference_spec.hpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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; }