1 //----------------------------------------------------------------------------- 2 // boost variant/detail/forced_return.hpp header file 3 // See http://www.boost.org for updates, documentation, and revision history. 4 //----------------------------------------------------------------------------- 5 // 6 // Copyright (c) 2003 Eric Friedman 7 // Copyright (c) 2015-2021 Antony Polukhin 8 // 9 // Distributed under the Boost Software License, Version 1.0. (See 10 // accompanying file LICENSE_1_0.txt or copy at 11 // http://www.boost.org/LICENSE_1_0.txt) 12 13 #ifndef BOOST_VARIANT_DETAIL_FORCED_RETURN_HPP 14 #define BOOST_VARIANT_DETAIL_FORCED_RETURN_HPP 15 16 #include <boost/config.hpp> 17 #include <boost/assert.hpp> 18 19 20 #ifdef BOOST_MSVC 21 # pragma warning( push ) 22 # pragma warning( disable : 4702 ) // unreachable code 23 #endif 24 25 namespace boost { namespace detail { namespace variant { 26 27 /////////////////////////////////////////////////////////////////////////////// 28 // (detail) function template forced_return 29 // 30 // Logical error to permit invocation at runtime, but (artificially) satisfies 31 // compile-time requirement of returning a result value. 32 // 33 template <typename T> 34 BOOST_NORETURN inline T forced_return()35forced_return() 36 { 37 // logical error: should never be here! (see above) 38 BOOST_ASSERT(false); 39 40 T (*dummy)() = 0; 41 (void)dummy; 42 BOOST_UNREACHABLE_RETURN(dummy()); 43 } 44 45 }}} // namespace boost::detail::variant 46 47 48 #ifdef BOOST_MSVC 49 # pragma warning( pop ) 50 #endif 51 52 #endif // BOOST_VARIANT_DETAIL_FORCED_RETURN_HPP 53