test: silence SonarCloud BUG: name truncate-via-temporary in clear_log()

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
fix/test-mysqlx-plugin-load-phase-b
Rene Cannao 3 weeks ago
parent ccc6648e06
commit baeca0e3dc

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

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

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

Loading…
Cancel
Save