From f81a0cb4b616d71379d7a213568fe2984a9e3787 Mon Sep 17 00:00:00 2001 From: Alexander Wilms Date: Sat, 13 Jan 2024 17:46:21 +0000 Subject: [PATCH 1/3] CLoggerBase: Remove semicolon from RAII_TRACE definition Fixes the following SonarCloud issue: Modify the macro definition so that it needs to be followed by a semicolon, or remove this empty statement. Empty statements should be removed cpp:S1116 https://sonarcloud.io/organizations/vcmi/rules?open=cpp%3AS1116&rule_key=cpp%3AS1116 --- include/vstd/CLoggerBase.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/vstd/CLoggerBase.h b/include/vstd/CLoggerBase.h index 37c9e5b94..0012b2dd1 100644 --- a/include/vstd/CLoggerBase.h +++ b/include/vstd/CLoggerBase.h @@ -173,9 +173,8 @@ private: /// the first statement in the function. Logging traces via this macro have almost no impact when the trace is disabled. /// #define RAII_TRACE(logger, onEntry, onLeave) \ - std::unique_ptr ctl00; \ if(logger->isTraceEnabled()) \ - ctl00 = std::make_unique(logger, onEntry, onLeave); + std::unique_ptr ctl00 = std::make_unique(logger, onEntry, onLeave) #define LOG_TRACE(logger) RAII_TRACE(logger, \ boost::str(boost::format("Entering %s.") % BOOST_CURRENT_FUNCTION), \ From d2b105f216bcebcc02e2d20b74b3726459621c55 Mon Sep 17 00:00:00 2001 From: Alexander Wilms Date: Sun, 14 Jan 2024 13:32:38 +0000 Subject: [PATCH 2/3] CLoggerBase: Use IvanSavenko's single-statement macro so that ct100 is not immediately destroyed --- include/vstd/CLoggerBase.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/include/vstd/CLoggerBase.h b/include/vstd/CLoggerBase.h index 0012b2dd1..546b3d352 100644 --- a/include/vstd/CLoggerBase.h +++ b/include/vstd/CLoggerBase.h @@ -172,9 +172,10 @@ private: /// Macros for tracing the control flow of the application conveniently. If the LOG_TRACE macro is used it should be /// the first statement in the function. Logging traces via this macro have almost no impact when the trace is disabled. /// -#define RAII_TRACE(logger, onEntry, onLeave) \ - if(logger->isTraceEnabled()) \ - std::unique_ptr ctl00 = std::make_unique(logger, onEntry, onLeave) +#define RAII_TRACE(logger, onEntry, onLeave) \ + std::unique_ptr ctl00 = logger->isTraceEnabled() ? \ + std::make_unique(logger, onEntry, onLeave) : \ + std::unique_ptr() #define LOG_TRACE(logger) RAII_TRACE(logger, \ boost::str(boost::format("Entering %s.") % BOOST_CURRENT_FUNCTION), \ From bc781c28e017b8f12133daa350c5344dfc8aed05 Mon Sep 17 00:00:00 2001 From: Alexander Wilms Date: Sun, 14 Jan 2024 14:00:32 +0000 Subject: [PATCH 3/3] Remove trailing semicolon from NET_EVENT_HANDLER macro --- AI/Nullkiller/AIGateway.cpp | 2 +- AI/VCAI/VCAI.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/AI/Nullkiller/AIGateway.cpp b/AI/Nullkiller/AIGateway.cpp index a5234bf47..0d79173a4 100644 --- a/AI/Nullkiller/AIGateway.cpp +++ b/AI/Nullkiller/AIGateway.cpp @@ -64,7 +64,7 @@ struct SetGlobalState }; -#define SET_GLOBAL_STATE(ai) SetGlobalState _hlpSetState(ai); +#define SET_GLOBAL_STATE(ai) SetGlobalState _hlpSetState(ai) #define NET_EVENT_HANDLER SET_GLOBAL_STATE(this) #define MAKING_TURN SET_GLOBAL_STATE(this) diff --git a/AI/VCAI/VCAI.cpp b/AI/VCAI/VCAI.cpp index 4ebeb1f3f..429f6a0db 100644 --- a/AI/VCAI/VCAI.cpp +++ b/AI/VCAI/VCAI.cpp @@ -66,7 +66,7 @@ struct SetGlobalState }; -#define SET_GLOBAL_STATE(ai) SetGlobalState _hlpSetState(ai); +#define SET_GLOBAL_STATE(ai) SetGlobalState _hlpSetState(ai) #define NET_EVENT_HANDLER SET_GLOBAL_STATE(this) #define MAKING_TURN SET_GLOBAL_STATE(this)