Skip to content

Commit e434d5e

Browse files
committed
test.cpp: fixed compiler warnings about missing returns after fully covered switch
1 parent 90e5701 commit e434d5e

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

test.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,28 @@ static int numberOfFailedAssertions = 0;
3636
#define ASSERT_EQUALS(expected, actual) (assertEquals((expected), (actual), __LINE__))
3737
#define ASSERT_THROW_EQUALS(stmt, e, expected) do { try { stmt; assertThrowFailed(__LINE__); } catch (const e& ex) { assertEquals((expected), (ex.what()), __LINE__); } } while (false)
3838

39+
#if __has_cpp_attribute (noreturn) \
40+
|| (defined(__GNUC__) && (__GNUC__ >= 5)) \
41+
|| defined(__clang__) \
42+
|| defined(__CPPCHECK__)
43+
# define NORETURN [[noreturn]]
44+
#elif defined(__GNUC__)
45+
# define NORETURN __attribute__((noreturn))
46+
#else
47+
# define NORETURN
48+
#endif
49+
50+
NORETURN inline void unreachable()
51+
{
52+
#if defined(__GNUC__)
53+
__builtin_unreachable();
54+
#elif defined(_MSC_VER)
55+
__assume(false);
56+
#else
57+
# error "no unreachable implementation"
58+
#endif
59+
}
60+
3961
static std::string pprint(const std::string &in)
4062
{
4163
std::string ret;
@@ -54,6 +76,8 @@ static const char* inputString(Input input) {
5476
case Input::CharBuffer:
5577
return "CharBuffer";
5678
}
79+
80+
unreachable();
5781
}
5882

5983
static int assertEquals(const std::string &expected, const std::string &actual, int line)
@@ -105,6 +129,8 @@ static simplecpp::TokenList makeTokenList(const char code[], std::size_t size, s
105129
case Input::CharBuffer:
106130
return {{code, size}, filenames, filename, outputList};
107131
}
132+
133+
unreachable();
108134
}
109135

110136
static simplecpp::TokenList makeTokenList(const char code[], std::vector<std::string> &filenames, const std::string &filename=std::string(), simplecpp::OutputList *outputList=nullptr)

0 commit comments

Comments
 (0)