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-2016 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/variant/detail/generic_result_type.hpp>
18 #include <boost/assert.hpp>
19 #include <cstdlib> // std::abort
20 
21 
22 #ifdef BOOST_MSVC
23 # pragma warning( push )
24 # pragma warning( disable : 4702 ) // unreachable code
25 #endif
26 
27 namespace boost { namespace detail { namespace variant {
28 
forced_return_no_return()29 BOOST_NORETURN inline void forced_return_no_return() { // fixes `must return a value` warnings
30     using namespace std;
31     abort(); // some implementations have no std::abort
32 }
33 
34 
35 ///////////////////////////////////////////////////////////////////////////////
36 // (detail) function template forced_return
37 //
38 // Logical error to permit invocation at runtime, but (artificially) satisfies
39 // compile-time requirement of returning a result value.
40 //
41 template <typename T>
42 BOOST_NORETURN inline
BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(T)43     BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(T)
44 forced_return()
45 {
46     // logical error: should never be here! (see above)
47     BOOST_ASSERT(false);
48 
49     forced_return_no_return();
50 
51 #ifdef BOOST_NO_NORETURN
52     BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(T) (*dummy)() = 0;
53     return dummy();
54 #endif
55 }
56 
57 }}} // namespace boost::detail::variant
58 
59 
60 #ifdef BOOST_MSVC
61 # pragma warning( pop )
62 #endif
63 
64 #endif // BOOST_VARIANT_DETAIL_FORCED_RETURN_HPP
65