Skip to content

Commit 927da20

Browse files
Adds solidity::util::unreachable() helper function.
1 parent 87f5865 commit 927da20

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

libsolutil/Assertions.h

+22
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,28 @@ namespace solidity::util
4040
#define ETH_FUNC __func__
4141
#endif
4242

43+
#if defined(__GNUC__)
44+
// GCC 4.8+, Clang, Intel and other compilers compatible with GCC (-std=c++0x or above)
45+
[[noreturn]] inline __attribute__((always_inline)) void unreachable()
46+
{
47+
__builtin_unreachable();
48+
}
49+
50+
#elif defined(_MSC_VER) // MSVC
51+
52+
[[noreturn]] __forceinline void unreachable()
53+
{
54+
__assume(false);
55+
}
56+
57+
#else
58+
59+
[[noreturn]] inline void unreachable()
60+
{
61+
solThrow(Exception, "Unreachable");
62+
}
63+
#endif
64+
4365
namespace assertions
4466
{
4567

0 commit comments

Comments
 (0)