From 2fca06ff6da5c67465b591f4d45e8fd14d531142 Mon Sep 17 00:00:00 2001 From: Alvin Date: Tue, 24 Nov 2020 13:23:13 +0900 Subject: [PATCH] Fix compiler warnings and condition check improvements (#390) * fix compiler warnings - loglevels.cpp - warns about double return if dynamic logging is on - crash handler_unix.cpp - warns about unused variable --- src/crashhandler_unix.cpp | 2 +- src/g3log/g3log.hpp | 6 +++--- src/loglevels.cpp | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/crashhandler_unix.cpp b/src/crashhandler_unix.cpp index 92de51b4..a14985e6 100644 --- a/src/crashhandler_unix.cpp +++ b/src/crashhandler_unix.cpp @@ -59,7 +59,7 @@ namespace { // Dump of stack,. then exit through g3log background worker // ALL thanks to this thread at StackOverflow. Pretty much borrowed from: // Ref: http://stackoverflow.com/questions/77005/how-to-generate-a-stacktrace-when-my-gcc-c-app-crashes - void signalHandler(int signal_number, siginfo_t* info, void* unused_context) { + void signalHandler(int signal_number, siginfo_t* /*info*/, void* /*unused_context*/) { // Only one signal will be allowed past this point if (false == shouldDoExit()) { diff --git a/src/g3log/g3log.hpp b/src/g3log/g3log.hpp index 35dad136..fb841245 100644 --- a/src/g3log/g3log.hpp +++ b/src/g3log/g3log.hpp @@ -145,12 +145,12 @@ namespace g3 { // LOG(level) is the API for the stream log -#define LOG(level) if(!g3::logLevel(level)) {} else INTERNAL_LOG_MESSAGE(level).stream() +#define LOG(level) if (!g3::logLevel(level)) {} else INTERNAL_LOG_MESSAGE(level).stream() // 'Conditional' stream log #define LOG_IF(level, boolean_expression) \ - if (false == (boolean_expression) || !g3::logLevel(level)) {} else INTERNAL_LOG_MESSAGE(level).stream() + if (!g3::logLevel(level) || false == (boolean_expression)) {} else INTERNAL_LOG_MESSAGE(level).stream() // 'Design By Contract' stream API. Broken Contracts will exit the application by using fatal signal SIGABRT // For unit testing, you can override the fatal handling using setFatalExitHandler(...). See tes_io.cpp for examples @@ -211,7 +211,7 @@ And here is possible output // Conditional log printf syntax #define LOGF_IF(level,boolean_expression, printf_like_message, ...) \ - if (false == (boolean_expression) || !g3::logLevel(level)) {} else INTERNAL_LOG_MESSAGE(level).capturef(printf_like_message, ##__VA_ARGS__) + if (!g3::logLevel(level) || false == (boolean_expression)) {} else INTERNAL_LOG_MESSAGE(level).capturef(printf_like_message, ##__VA_ARGS__) // Design By Contract, printf-like API syntax with variadic input parameters. // Calls the signal handler if the contract failed with the default exit for a failed contract. This is typically SIGABRT diff --git a/src/loglevels.cpp b/src/loglevels.cpp index c081a4bd..e4dd5486 100644 --- a/src/loglevels.cpp +++ b/src/loglevels.cpp @@ -132,7 +132,8 @@ namespace g3 { int level = log_level.value; bool status = internal::g_log_levels[level].status.value(); return status; -#endif +#else return true; +#endif } } // g3