From 79b6525ba0ac749ebe3581ca892039760d58b638 Mon Sep 17 00:00:00 2001 From: Stefan van Kessel Date: Sat, 11 Nov 2023 11:46:15 +0100 Subject: [PATCH 1/3] Minor: fix msvc warning "not all control paths return a value" 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 https://github.com/danmar/cppcheck/pull/5497) --- lib/config.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/config.h b/lib/config.h index 3ecff1c1000..49f76698ee1 100644 --- a/lib/config.h +++ b/lib/config.h @@ -57,7 +57,12 @@ # define NORETURN [[noreturn]] #elif defined(__GNUC__) # define NORETURN __attribute__((noreturn)) -#else +#elif defined __has_cpp_attribute +# if __has_cpp_attribute (noreturn) +# define NORETURN [[noreturn]] +# endif +#endif +#if !defined(NORETURN) # define NORETURN #endif From 7bcdf4a6c786a2ca0dc70dc41d45932ba6705bbf Mon Sep 17 00:00:00 2001 From: Stefan van Kessel Date: Sun, 12 Nov 2023 11:42:39 +0100 Subject: [PATCH 2/3] Minor: fix msvc warning "not all control paths return a value" Moved __has_cpp_attribute block up to first choice. When we have a portable standard way of expressing it, that's the best choice. (Addresses Review Feedback from Firewave) --- lib/config.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/config.h b/lib/config.h index 49f76698ee1..53265085de0 100644 --- a/lib/config.h +++ b/lib/config.h @@ -51,19 +51,21 @@ #endif // C++11 noreturn -#if (defined(__GNUC__) && (__GNUC__ >= 5)) \ - || defined(__clang__) \ - || defined(__CPPCHECK__) -# define NORETURN [[noreturn]] -#elif defined(__GNUC__) -# define NORETURN __attribute__((noreturn)) -#elif defined __has_cpp_attribute +#if defined __has_cpp_attribute # if __has_cpp_attribute (noreturn) # define NORETURN [[noreturn]] # endif #endif #if !defined(NORETURN) -# define NORETURN +# if (defined(__GNUC__) && (__GNUC__ >= 5)) \ + || defined(__clang__) \ + || defined(__CPPCHECK__) +# define NORETURN [[noreturn]] +# elif defined(__GNUC__) +# define NORETURN __attribute__((noreturn)) +# else +# define NORETURN +# endif #endif // fallthrough From b3e07d45c54a9c8433fae5206b0e1761ae252610 Mon Sep 17 00:00:00 2001 From: Stefan van Kessel Date: Sun, 12 Nov 2023 11:58:17 +0100 Subject: [PATCH 3/3] Fix formatting / run uncrustify --- lib/config.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/config.h b/lib/config.h index 53265085de0..6cb34b5e40d 100644 --- a/lib/config.h +++ b/lib/config.h @@ -58,8 +58,8 @@ #endif #if !defined(NORETURN) # if (defined(__GNUC__) && (__GNUC__ >= 5)) \ - || defined(__clang__) \ - || defined(__CPPCHECK__) + || defined(__clang__) \ + || defined(__CPPCHECK__) # define NORETURN [[noreturn]] # elif defined(__GNUC__) # define NORETURN __attribute__((noreturn))