mirror of
https://gitlab.kitware.com/cmake/cmake.git
synced 2026-09-25 04:09:36 +03:00
In debug builds, we assert and abort to give more useful crashes for development (i.e., instead of triggering UB). Otherwise, we get the optimization benefits of `unreachable()` (or the older platform-specific fallbacks per `cm/utility`).
23 lines
1.0 KiB
C++
23 lines
1.0 KiB
C++
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
file LICENSE.rst or https://cmake.org/licensing for details. */
|
|
#pragma once
|
|
|
|
#if defined(NDEBUG)
|
|
# include <cm/utility>
|
|
# define CM_UNREACHABLE \
|
|
do { \
|
|
cm::unreachable(); \
|
|
} while (false)
|
|
#else
|
|
# include <cassert>
|
|
# include <cstdlib>
|
|
# include <iostream>
|
|
# define CM_UNREACHABLE \
|
|
do { \
|
|
std::cerr << "unreachable code path at " << __FILE__ << ':' << __LINE__ \
|
|
<< " in " << __func__ << '\n'; \
|
|
assert(false && "unreachable code path"); \
|
|
std::abort(); \
|
|
} while (false)
|
|
#endif
|