mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-11-10 21:19:43 +01:00
Add Unreachable.h
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.)
This commit is contained in:
parent
c177f456f4
commit
7a48d0a53e
1 changed files with 17 additions and 0 deletions
17
desktop_version/src/Unreachable.h
Normal file
17
desktop_version/src/Unreachable.h
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
#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 */
|
Loading…
Reference in a new issue