Source: Add std::unreachable from C++23

This commit is contained in:
Tyler Yankee
2026-08-26 13:24:34 -04:00
parent 10b4bf7e1e
commit be415ecb74
+34
View File
@@ -9,6 +9,13 @@
# define CMake_HAVE_CXX_IN_PLACE
#endif
#if (__cplusplus >= 202302L || \
(defined(_MSVC_LANG) && _MSVC_LANG >= 202302L)) && \
defined(__cpp_lib_unreachable) && (__cpp_lib_unreachable >= 202202L)
# define CMake_HAVE_CXX_UNREACHABLE
#endif
#include <cstdlib> // IWYU pragma: export
#include <utility> // IWYU pragma: export
namespace cm {
@@ -27,5 +34,32 @@ struct in_place_t
constexpr in_place_t in_place{};
#endif
#if defined(CMake_HAVE_CXX_UNREACHABLE)
using std::unreachable;
#else
[[noreturn]] inline void unreachable()
{
# if defined(_MSC_VER)
__assume(0);
std::abort();
# elif defined(__has_builtin)
# if __has_builtin(__builtin_unreachable)
__builtin_unreachable();
# else
std::abort();
# endif
# elif defined(__GNUC__) && defined(__GNUC_MINOR__) && \
((__GNUC__ * 100 + __GNUC_MINOR__) >= 405)
__builtin_unreachable();
# else
std::abort();
# endif
}
#endif
}