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() {