@@ -37,6 +37,28 @@ static int numberOfFailedAssertions = 0;
3737#define ASSERT_EQUALS (expected, actual ) (assertEquals((expected), (actual), __LINE__))
3838#define ASSERT_THROW_EQUALS (stmt, e, expected ) do { try { stmt; assertThrowFailed (__LINE__); } catch (const e& ex) { assertEquals ((expected), (ex.what ()), __LINE__); } } while (false )
3939
40+ #if __has_cpp_attribute (noreturn) \
41+ || (defined (__GNUC__) && (__GNUC__ >= 5 )) \
42+ || defined (__clang__) \
43+ || defined (__CPPCHECK__)
44+ # define NORETURN [[noreturn]]
45+ #elif defined(__GNUC__)
46+ # define NORETURN __attribute__ ((noreturn))
47+ #else
48+ # define NORETURN
49+ #endif
50+
51+ NORETURN static void unreachable ()
52+ {
53+ #if defined(__GNUC__)
54+ __builtin_unreachable ();
55+ #elif defined(_MSC_VER)
56+ __assume (false );
57+ #else
58+ # error "no unreachable implementation"
59+ #endif
60+ }
61+
4062static std::string pprint (const std::string &in)
4163{
4264 std::string ret;
@@ -55,6 +77,8 @@ static const char* inputString(Input input) {
5577 case Input::CharBuffer:
5678 return " CharBuffer" ;
5779 }
80+
81+ unreachable ();
5882}
5983
6084static int assertEquals (const std::string &expected, const std::string &actual, int line)
@@ -106,6 +130,8 @@ static simplecpp::TokenList makeTokenList(const char code[], std::size_t size, s
106130 case Input::CharBuffer:
107131 return {{code, size}, filenames, filename, outputList};
108132 }
133+
134+ unreachable ();
109135}
110136
111137static simplecpp::TokenList makeTokenList (const char code[], std::vector<std::string> &filenames, const std::string &filename=std::string(), simplecpp::OutputList *outputList=nullptr)
0 commit comments