From ab0d8674114f0c1006d6e0566355549cc68414d1 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Wed, 31 May 2017 05:36:35 +0300 Subject: [PATCH] Another attempt at g+ 5 fix --- include/boost/variant2/variant.hpp | 36 ++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) 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)