Files
cmake/Source/cmUnreachable.h
T
Tyler Yankee f460a199e3 Source: Add and use CM_UNREACHABLE macro
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`).
2026-08-26 13:24:34 -04:00

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