From baeca0e3dcb18147dbeed98ac024584f66d7fc51 Mon Sep 17 00:00:00 2001 From: Rene Cannao Date: Mon, 27 Apr 2026 04:30:05 +0000 Subject: [PATCH] test: silence SonarCloud BUG: name truncate-via-temporary in clear_log() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Three identical SonarCloud BUG-severity findings (one per file) on the truncate-via-temporary idiom: std::ofstream(g_log_path, std::ios::trunc); This creates a temporary std::ofstream whose destructor closes the file — the truncate is the intended side effect. SonarCloud's rule "Name this unused temporary object or remove it" does not understand the side-effect pattern and flags it as a BUG. Issue #5674 triaged all 3 BUG findings as false positives. This commit silences them with the cosmetic fix recommended in that issue: give the temporary a name and (void)-cast it. Same generated code, no behaviour change, but Sonar stops flagging it. Files: test/tap/tests/unit/plugin_{config,lifecycle,manager}_unit-t.cpp --- test/tap/tests/unit/plugin_config_unit-t.cpp | 4 +++- test/tap/tests/unit/plugin_lifecycle_unit-t.cpp | 4 +++- test/tap/tests/unit/plugin_manager_unit-t.cpp | 8 +++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/test/tap/tests/unit/plugin_config_unit-t.cpp b/test/tap/tests/unit/plugin_config_unit-t.cpp index 6a8cb3d6e..81f0d47ac 100644 --- a/test/tap/tests/unit/plugin_config_unit-t.cpp +++ b/test/tap/tests/unit/plugin_config_unit-t.cpp @@ -38,7 +38,9 @@ void make_log_path() { void clear_log() { if (g_log_path.empty()) return; - std::ofstream(g_log_path, std::ios::trunc); + // See plugin_manager_unit-t.cpp for the SonarCloud rationale. + std::ofstream truncate_handle(g_log_path, std::ios::trunc); + (void)truncate_handle; } std::string read_log() { diff --git a/test/tap/tests/unit/plugin_lifecycle_unit-t.cpp b/test/tap/tests/unit/plugin_lifecycle_unit-t.cpp index e8a6c74f3..5830455ab 100644 --- a/test/tap/tests/unit/plugin_lifecycle_unit-t.cpp +++ b/test/tap/tests/unit/plugin_lifecycle_unit-t.cpp @@ -48,7 +48,9 @@ void make_log_path() { void clear_log() { if (g_log_path.empty()) return; - std::ofstream(g_log_path, std::ios::trunc); + // See plugin_manager_unit-t.cpp for the SonarCloud rationale. + std::ofstream truncate_handle(g_log_path, std::ios::trunc); + (void)truncate_handle; } std::string read_log() { diff --git a/test/tap/tests/unit/plugin_manager_unit-t.cpp b/test/tap/tests/unit/plugin_manager_unit-t.cpp index f01acdb67..4ebe11dc8 100644 --- a/test/tap/tests/unit/plugin_manager_unit-t.cpp +++ b/test/tap/tests/unit/plugin_manager_unit-t.cpp @@ -35,7 +35,13 @@ void make_log_path() { void clear_log() { if (g_log_path.empty()) return; - std::ofstream(g_log_path, std::ios::trunc); + // Truncate via constructor + immediate destructor. The named local + // variable is intentional: SonarCloud's "Name this unused temporary + // object" rule does not recognise the truncate-via-temporary idiom, + // and the cosmetic name silences the false positive without changing + // behaviour. + std::ofstream truncate_handle(g_log_path, std::ios::trunc); + (void)truncate_handle; } std::string read_log() {