mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-06-25 22:18:30 +02:00
7a48d0a53e
This is to indicate when a code path is absolutely, for certain, 100% unreachable. Useful as the default case inside a case-switch that is for sure 100% exhaustive because it's inside the case of another case-switch (and the default case is there to suppress compiler warnings about the case-switch not being exhaustive), which is a situation coming up in my scriptclass::startgamemode refactor. It does this by deliberately invoking undefined behavior, either using a compiler builtin that does the same thing or being a noreturn function that returns. (And undefined behavior is not undefined behavior if it is not executed in a code path, otherwise all NULL checks would be useless because it'd dereference something that could be NULL in another code path.)
18 lines
451 B
C
18 lines
451 B
C
#ifndef UNREACHABLE_H
|
|
#define UNREACHABLE_H
|
|
|
|
#include <SDL_stdinc.h>
|
|
|
|
SDL_NORETURN SDL_INLINE void VVV_unreachable(void)
|
|
{
|
|
/* __builtin_unreachable() and __assume(0) execute undefined behavior.
|
|
* Otherwise, a noreturn function returning is also undefined behavior. */
|
|
#if defined(__has_builtin) && __has_builtin(__builtin_unreachable)
|
|
__builtin_unreachable();
|
|
#elif defined(_MSC_VER)
|
|
__assume(0);
|
|
#endif
|
|
}
|
|
|
|
#endif /* UNREACHABLE_H */
|