Skip to content

Commit d352094

Browse files
authored
Minor: fix msvc warning "not all control paths return a value" (#5650)
When building with /Od - default cmake debug build for me, the __assume(false); trick does not work to get rid of the C4714 warnings https://godbolt.org/z/a6xGnfP7d D:\tmp\cppcheck\lib\keywords.cpp(205): warning C4715: 'Keywords::getOnly': not all control paths return a value D:\tmp\cppcheck\lib\keywords.cpp(226): warning C4715: 'Keywords::getOnly': not all control paths return a value D:\tmp\cppcheck\lib\keywords.cpp(168): warning C4715: 'Keywords::getAll': not all control paths return a value D:\tmp\cppcheck\lib\keywords.cpp(188): warning C4715: 'Keywords::getAll': not all control paths return a value Proposed fix: also define NORETURN to [[noreturn]] when according to __has_cpp_attribute [[noreturn]] is supported https://en.cppreference.com/w/cpp/feature_test (For previous discussion see also #5497)
1 parent b201ef2 commit d352094

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

lib/config.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,21 @@
5151
#endif
5252

5353
// C++11 noreturn
54-
#if (defined(__GNUC__) && (__GNUC__ >= 5)) \
54+
#if defined __has_cpp_attribute
55+
# if __has_cpp_attribute (noreturn)
56+
# define NORETURN [[noreturn]]
57+
# endif
58+
#endif
59+
#if !defined(NORETURN)
60+
# if (defined(__GNUC__) && (__GNUC__ >= 5)) \
5561
|| defined(__clang__) \
5662
|| defined(__CPPCHECK__)
57-
# define NORETURN [[noreturn]]
58-
#elif defined(__GNUC__)
59-
# define NORETURN __attribute__((noreturn))
60-
#else
61-
# define NORETURN
63+
# define NORETURN [[noreturn]]
64+
# elif defined(__GNUC__)
65+
# define NORETURN __attribute__((noreturn))
66+
# else
67+
# define NORETURN
68+
# endif
6269
#endif
6370

6471
// fallthrough

0 commit comments

Comments
 (0)