Skip to content

Commit 2d39af5

Browse files
committed
only issue logChecker messages when necessary [skip ci]
1 parent 5d936c0 commit 2d39af5

4 files changed

Lines changed: 20 additions & 8 deletions

File tree

cli/cppcheckexecutor.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,7 @@ int CppCheckExecutor::check_internal(const Settings& settings, Suppressions& sup
501501

502502
void StdLogger::writeCheckersReport(const Suppressions& supprs)
503503
{
504+
// TODO: only necessary when we actually issue a checkers report?
504505
if (!mCheckersFile.empty())
505506
{
506507
std::ofstream fout(mCheckersFile);
@@ -510,11 +511,9 @@ void StdLogger::writeCheckersReport(const Suppressions& supprs)
510511
}
511512
}
512513

513-
const bool summary = mSettings.safety || mSettings.severity.isEnabled(Severity::information);
514-
const bool xmlReport = mSettings.outputFormat == Settings::OutputFormat::xml && mSettings.xml_version == 3;
515-
const bool textReport = !mSettings.checkersReportFilename.empty();
514+
bool summary, xmlReport, textReport;
516515

517-
if (!summary && !xmlReport && !textReport)
516+
if (!mSettings.collectLogCheckers(&summary, &xmlReport, &textReport))
518517
return;
519518

520519
CheckersReport checkersReport(mSettings, mActiveCheckers);

lib/check.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ ErrorPath Check::getErrorPath(const Token* errtok, const ValueFlow::Value* value
130130

131131
void Check::logChecker(const char id[])
132132
{
133-
// TODO: only issue when we would actually use it later on
134-
reportError(nullptr, Severity::internal, "logChecker", id);
133+
if (!mSettings->buildDir.empty() || mSettings->collectLogCheckers())
134+
reportError(nullptr, Severity::internal, "logChecker", id);
135135
}
136136

lib/settings.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,20 @@ class CPPCHECKLIB WARN_UNUSED Settings {
596596

597597
static bool unusedFunctionOnly();
598598

599+
bool collectLogCheckers(bool* summary = nullptr, bool* xmlReport = nullptr, bool* textReport = nullptr) const {
600+
const bool s = safety || severity.isEnabled(Severity::information);
601+
if (summary)
602+
*summary = s;
603+
const bool x = outputFormat == Settings::OutputFormat::xml && xml_version == 3;
604+
if (xmlReport)
605+
*xmlReport = x;
606+
const bool t = !checkersReportFilename.empty();
607+
if (textReport)
608+
*textReport = t;
609+
610+
return s || x || t;
611+
}
612+
599613
private:
600614
static std::string parseEnabled(const std::string &str, std::tuple<SimpleEnableGroup<Severity>, SimpleEnableGroup<Checks>> &groups);
601615
std::string applyEnabled(const std::string &str, bool enable);

test/cli/other_test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4636,9 +4636,8 @@ def test_dui_include_absolute_missing(tmp_path): # #14675
46364636
]
46374637

46384638

4639-
@pytest.mark.xfail(strict=True) # TODO: should not report logChecker when not required
46404639
@pytest.mark.skipif(sys.platform == 'win32', reason="requires ProcessExecutor")
4641-
def test_ipc_log_checker(tmp_path):
4640+
def test_ipc(tmp_path):
46424641
test_file = tmp_path / 'test.c'
46434642
with open(test_file, "w") as f:
46444643
f.write('void f() {}')

0 commit comments

Comments
 (0)