forced_return.hpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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-2019 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. #ifndef BOOST_VARIANT_DETAIL_FORCED_RETURN_HPP
  13. #define BOOST_VARIANT_DETAIL_FORCED_RETURN_HPP
  14. #include <boost/config.hpp>
  15. #include <boost/assert.hpp>
  16. #ifdef BOOST_MSVC
  17. # pragma warning( push )
  18. # pragma warning( disable : 4702 ) // unreachable code
  19. #endif
  20. namespace boost { namespace detail { namespace variant {
  21. ///////////////////////////////////////////////////////////////////////////////
  22. // (detail) function template forced_return
  23. //
  24. // Logical error to permit invocation at runtime, but (artificially) satisfies
  25. // compile-time requirement of returning a result value.
  26. //
  27. template <typename T>
  28. BOOST_NORETURN inline T
  29. forced_return()
  30. {
  31. // logical error: should never be here! (see above)
  32. BOOST_ASSERT(false);
  33. T (*dummy)() = 0;
  34. (void)dummy;
  35. BOOST_UNREACHABLE_RETURN(dummy());
  36. }
  37. }}} // namespace boost::detail::variant
  38. #ifdef BOOST_MSVC
  39. # pragma warning( pop )
  40. #endif
  41. #endif // BOOST_VARIANT_DETAIL_FORCED_RETURN_HPP