From f999d879d5a97169638e7080c4b2eddfe76f875d Mon Sep 17 00:00:00 2001 From: Steven Cartmell <45599587+Ruffel@users.noreply.github.com> Date: Fri, 28 Feb 2020 21:09:31 +0000 Subject: [PATCH 01/11] fix: Break from loop on last iteration to resolve clang-tidy warning The clang-tidy warning `clang-analyzer-cplusplus.Move` warns when a moved from object is deferenced. This is triggered in spdlog because clang-tidy fails to detect that the `logger:set_formatter` will only move the unique_ptr on the last iteration of the loop, assuming that `f->clone` may be called on it afterwards. To fix, add a break statement after moving the pointer (on the last iteration) to let clang-tidy know the logger pointer is not used after this point. --- include/spdlog/logger-inl.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/spdlog/logger-inl.h b/include/spdlog/logger-inl.h index 95a485f1..c1e01657 100644 --- a/include/spdlog/logger-inl.h +++ b/include/spdlog/logger-inl.h @@ -89,6 +89,8 @@ SPDLOG_INLINE void logger::set_formatter(std::unique_ptr f) { // last element - we can be move it. (*it)->set_formatter(std::move(f)); + + break; } else { From 0120dcc787b818f2ce3207467e1c1515360f5385 Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Sat, 29 Feb 2020 13:20:26 +0200 Subject: [PATCH 02/11] Update logger-inl.h --- include/spdlog/logger-inl.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/spdlog/logger-inl.h b/include/spdlog/logger-inl.h index c1e01657..d9d58c29 100644 --- a/include/spdlog/logger-inl.h +++ b/include/spdlog/logger-inl.h @@ -89,8 +89,7 @@ SPDLOG_INLINE void logger::set_formatter(std::unique_ptr f) { // last element - we can be move it. (*it)->set_formatter(std::move(f)); - - break; + break; // to prevent clang-tidy warning } else { From 62189602cb3719cb0450fdcd2a0ec44e84c2f9ad Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Tue, 3 Mar 2020 09:51:56 +0200 Subject: [PATCH 03/11] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index aab2b04c..1a361502 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ $ cmake .. && make -j * Headers only, just copy and use. Or use as a compiled library. * Feature rich formatting, using the excellent [fmt](https://github.com/fmtlib/fmt) library. * **New!** [Backtrace](#backtrace-support) support - store debug messages in a ring buffer and display later on demand. -* Fast asynchronous mode (optional) +* Asynchronous mode (optional) * [Custom](https://github.com/gabime/spdlog/wiki/3.-Custom-formatting) formatting. * Multi/Single threaded loggers. * Various log targets: From 817d2764b64bfff95c1f1cf35f46c8f43b91ade1 Mon Sep 17 00:00:00 2001 From: gabime Date: Tue, 3 Mar 2020 23:53:28 +0200 Subject: [PATCH 04/11] Fix bench tidy warning --- tests/test_errors.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_errors.cpp b/tests/test_errors.cpp index 613a9012..e22fafef 100644 --- a/tests/test_errors.cpp +++ b/tests/test_errors.cpp @@ -9,7 +9,7 @@ class failing_sink : public spdlog::sinks::base_sink { public: failing_sink() = default; - ~failing_sink() final = default; + ~failing_sink() = default; protected: void sink_it_(const spdlog::details::log_msg &) final From 6095db951baf343b165ad0a9fdee2a09df6f6f64 Mon Sep 17 00:00:00 2001 From: Gabi Melman Date: Wed, 4 Mar 2020 14:12:56 +0200 Subject: [PATCH 05/11] Update README.md --- README.md | 9 --------- 1 file changed, 9 deletions(-) diff --git a/README.md b/README.md index 1a361502..42dd82ec 100644 --- a/README.md +++ b/README.md @@ -300,15 +300,6 @@ void android_example() android_logger->critical("Use \"adb shell logcat\" to view this message."); } ``` ---- -#### Compile-time format string syntax checking -```C++ -#include "spdlog/spdlog.h" -int main() -{ - spdlog::info(FMT_STRING("{:d} is an invalid format tag")); -} -``` ## Benchmarks From 8302086942af4dbe538d0e4438d876d1e03d1156 Mon Sep 17 00:00:00 2001 From: gabime Date: Wed, 4 Mar 2020 15:40:04 +0200 Subject: [PATCH 06/11] Fixed tcp_client --- include/spdlog/details/tcp_client.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/spdlog/details/tcp_client.h b/include/spdlog/details/tcp_client.h index 5b2f0af1..3052ac87 100644 --- a/include/spdlog/details/tcp_client.h +++ b/include/spdlog/details/tcp_client.h @@ -54,8 +54,8 @@ public: void connect(const std::string &host, int port) { close(); - spdlog::info("Connecting.."); - struct addrinfo hints{}; + struct addrinfo hints + {}; memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = AF_INET; // IPv4 hints.ai_socktype = SOCK_STREAM; // TCP From d7313a3274be8cdecf14b5a873abfd8252748a20 Mon Sep 17 00:00:00 2001 From: gabime Date: Wed, 4 Mar 2020 15:52:42 +0200 Subject: [PATCH 07/11] Fix tidy warning --- include/spdlog/sinks/win_eventlog_sink.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/spdlog/sinks/win_eventlog_sink.h b/include/spdlog/sinks/win_eventlog_sink.h index d9839110..3e858940 100644 --- a/include/spdlog/sinks/win_eventlog_sink.h +++ b/include/spdlog/sinks/win_eventlog_sink.h @@ -73,7 +73,7 @@ struct win32_error : public spdlog_ex return fmt::format("{}: {}{}", user_message, error_code, system_message); } - win32_error(std::string const &func_name, DWORD error = GetLastError()) + explicit win32_error(std::string const &func_name, DWORD error = GetLastError()) : spdlog_ex(format(func_name, error)) {} }; From 403795994590b781a1e6f801ad30d1b1f15f279d Mon Sep 17 00:00:00 2001 From: gabime Date: Wed, 4 Mar 2020 15:59:45 +0200 Subject: [PATCH 08/11] Fix tidy warning --- include/spdlog/details/pattern_formatter.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/spdlog/details/pattern_formatter.h b/include/spdlog/details/pattern_formatter.h index fa134ada..a5c035d1 100644 --- a/include/spdlog/details/pattern_formatter.h +++ b/include/spdlog/details/pattern_formatter.h @@ -92,7 +92,7 @@ private: // Extract given pad spec (e.g. %8X) // Advance the given it pass the end of the padding spec found (if any) // Return padding. - details::padding_info handle_padspec_(std::string::const_iterator &it, std::string::const_iterator end); + static details::padding_info handle_padspec_(std::string::const_iterator &it, std::string::const_iterator end); void compile_pattern_(const std::string &pattern); }; From b3402a0b9f68357986fe827000b966f6bdb4e76e Mon Sep 17 00:00:00 2001 From: gabime Date: Wed, 4 Mar 2020 16:08:35 +0200 Subject: [PATCH 09/11] Fix tidy warning --- include/spdlog/details/os-inl.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/spdlog/details/os-inl.h b/include/spdlog/details/os-inl.h index d77aab11..1b479c33 100644 --- a/include/spdlog/details/os-inl.h +++ b/include/spdlog/details/os-inl.h @@ -390,13 +390,13 @@ SPDLOG_INLINE int pid() SPDLOG_NOEXCEPT } // Determine if the terminal supports colors -// Source: https://github.com/agauniyal/rang/ +// Based on: https://github.com/agauniyal/rang/ SPDLOG_INLINE bool is_color_terminal() SPDLOG_NOEXCEPT { #ifdef _WIN32 return true; #else - static constexpr std::array Terms = { + static constexpr std::array terms = { {"ansi", "color", "console", "cygwin", "gnome", "konsole", "kterm", "linux", "msys", "putty", "rxvt", "screen", "vt100", "xterm"}}; const char *env_p = std::getenv("TERM"); @@ -406,7 +406,7 @@ SPDLOG_INLINE bool is_color_terminal() SPDLOG_NOEXCEPT } static const bool result = - std::any_of(std::begin(Terms), std::end(Terms), [&](const char *term) { return std::strstr(env_p, term) != nullptr; }); + std::any_of(terms.begin(), terms.end(), [&](const char *term) { return std::strstr(env_p, term) != nullptr; }); return result; #endif } From 1f8b04cbd145ca2415baec1dbf8de4edcead2782 Mon Sep 17 00:00:00 2001 From: gabime Date: Wed, 4 Mar 2020 16:09:04 +0200 Subject: [PATCH 10/11] Fix tidy warning --- include/spdlog/details/thread_pool-inl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/spdlog/details/thread_pool-inl.h b/include/spdlog/details/thread_pool-inl.h index 43220f43..2789abfa 100644 --- a/include/spdlog/details/thread_pool-inl.h +++ b/include/spdlog/details/thread_pool-inl.h @@ -113,7 +113,7 @@ bool SPDLOG_INLINE thread_pool::process_next_msg_() } default: { - assert(false && "Unexpected async_msg_type"); + assert(false); } } From 8284865f9ac52c15eeff13e8466013a81c365e88 Mon Sep 17 00:00:00 2001 From: gabime Date: Wed, 4 Mar 2020 16:21:07 +0200 Subject: [PATCH 11/11] Fix tidy warning --- include/spdlog/details/registry-inl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/spdlog/details/registry-inl.h b/include/spdlog/details/registry-inl.h index 562aa06c..95ab706c 100644 --- a/include/spdlog/details/registry-inl.h +++ b/include/spdlog/details/registry-inl.h @@ -184,7 +184,7 @@ SPDLOG_INLINE void registry::flush_on(level::level_enum log_level) SPDLOG_INLINE void registry::flush_every(std::chrono::seconds interval) { std::lock_guard lock(flusher_mutex_); - std::function clbk = std::bind(®istry::flush_all, this); + auto clbk = [this](){this->flush_all();}; periodic_flusher_ = details::make_unique(clbk, interval); }