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] 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 {