mirror of
https://gitlab.kitware.com/cmake/cmake.git
synced 2026-09-25 04:09:36 +03:00
Source: Add std::unreachable from C++23
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user