diff --git a/include/boost/variant2/variant.hpp b/include/boost/variant2/variant.hpp index 3506524..5b3fc76 100644 --- a/include/boost/variant2/variant.hpp +++ b/include/boost/variant2/variant.hpp @@ -116,9 +116,16 @@ template constexpr variant_alternative_t() ); + +#else + + if( v.index() != I ) throw bad_variant_access(); return v._get_impl( mp_size_t() ); + +#endif } template constexpr variant_alternative_t>&& get(variant&& v) @@ -134,9 +141,16 @@ template constexpr variant_alternative_t() ); + +#else + + if( v.index() != I ) throw bad_variant_access(); return v._get_impl( mp_size_t() ); + +#endif } template constexpr variant_alternative_t> const&& get(variant const&& v) @@ -155,9 +169,16 @@ template constexpr U& get(variant& v) static_assert( mp_count, U>::value == 1, "The type must occur exactly once in the list of variant alternatives" ); constexpr auto I = mp_find, U>::value; - if( v.index() != I ) throw bad_variant_access(); +#if BOOST_WORKAROUND( BOOST_GCC, < 60000 ) + return (void)( v.index() != I? throw bad_variant_access(): 0), v._get_impl( mp_size_t() ); + +#else + + if( v.index() != I ) throw bad_variant_access(); return v._get_impl( mp_size_t() ); + +#endif } template constexpr U&& get(variant&& v) @@ -175,9 +196,16 @@ template constexpr U const& get(variant const& v) static_assert( mp_count, U>::value == 1, "The type must occur exactly once in the list of variant alternatives" ); constexpr auto I = mp_find, U>::value; - if( v.index() != I ) throw bad_variant_access(); +#if BOOST_WORKAROUND( BOOST_GCC, < 60000 ) + return (void)( v.index() != I? throw bad_variant_access(): 0), v._get_impl( mp_size_t() ); + +#else + + if( v.index() != I ) throw bad_variant_access(); return v._get_impl( mp_size_t() ); + +#endif } template constexpr U const&& get(variant const&& v)