From: <sv...@op...> - 2024-03-03 15:34:47
|
Author: manx Date: Sun Mar 3 16:34:39 2024 New Revision: 20218 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=20218 Log: [Ref] mpt/base/utility.hpp: Add mpt::unreachable() for C++23 std::unreachable(). Modified: trunk/OpenMPT/src/mpt/base/utility.hpp Modified: trunk/OpenMPT/src/mpt/base/utility.hpp ============================================================================== --- trunk/OpenMPT/src/mpt/base/utility.hpp Sun Mar 3 16:32:41 2024 (r20217) +++ trunk/OpenMPT/src/mpt/base/utility.hpp Sun Mar 3 16:34:39 2024 (r20218) @@ -53,14 +53,14 @@ using std::to_underlying; -#else +#else // !C++23 template <typename T> constexpr std::underlying_type_t<T> to_underlying(T value) noexcept { return static_cast<typename std::underlying_type<T>::type>(value); } -#endif +#endif // C++23 @@ -193,6 +193,26 @@ +#if MPT_CXX_AT_LEAST(23) + +using std::unreachable; + +#else // !C++23 + +[[noreturn]] inline void unreachable() { +#if MPT_COMPILER_MSVC + __assume(false); +#elif MPT_COMPILER_GCC || MPT_COMPILER_CLANG + __builtin_unreachable(); +#else + return; +#endif +} + +#endif // C++23 + + + } // namespace MPT_INLINE_NS } // namespace mpt |