diff options
author | 2025-04-06 14:52:08 +0100 | |
---|---|---|
committer | 2025-04-06 20:59:36 +0100 | |
commit | 8af0cbed8c336b9bfaaac359e52d6b1b396ed489 (patch) | |
tree | 87b9fb5b6e70c929f172cfc8e4f53f67c9645be5 | |
parent | 586e13e3c2e03b36b092d5637e382665ed8ce416 (diff) | |
download | sst-8af0cbed8c336b9bfaaac359e52d6b1b396ed489.tar.gz sst-8af0cbed8c336b9bfaaac359e52d6b1b396ed489.zip |
Add portable unreachable macro, just for fun
This isn't useful to us at all, but might be useful to someone else.
I always try to write code for multiple compilers for this reason, even
if SST ultimately still requires Clang.
-rw-r--r-- | src/langext.h | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/langext.h b/src/langext.h index 8d3ee6e..0a17cb2 100644 --- a/src/langext.h +++ b/src/langext.h @@ -26,8 +26,9 @@ #define assume(x) ((void)(__assume(x), 0)) #define cold __declspec(noinline) #else -#define unreachable ((void)(0)) // might still give some warnings, but too bad -#define assume(x) ((void)0) +static inline _Noreturn void _invoke_ub(void) {} +#define unreachable (_invoke_ub()) +#define assume(x) ((void)(!!(x) || (_invoke_ub(), 0))) #define cold #endif #endif |