Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,8 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
};

bool executorAuto = true;
bool enableInformation = false;
bool enableUnmatchedSuppression = false;

for (int i = 1; i < argc; i++) {
if (argv[i][0] != '-') {
Expand Down Expand Up @@ -694,6 +696,12 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
mSettings.addEnabled("performance");
mSettings.addEnabled("portability");
}
if (enable_arg.find("information") != std::string::npos) {
enableInformation = true;
}
if (enable_arg.find("unmatchedSuppression") != std::string::npos) {
enableUnmatchedSuppression = true;
}
}

// --error-exitcode=1
Expand Down Expand Up @@ -1575,6 +1583,9 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
}
}

if (enableInformation && !enableUnmatchedSuppression)
mLogger.printMessage("unmatchedSuppression is no longer included in --enable=information starting with Cppcheck 2.18. Please use --enable=unmatchedSuppression instead.");

// TODO: bail out?
if (!executorAuto && mSettings.useSingleJob())
mLogger.printMessage("'--executor' has no effect as only a single job will be used.");
Expand Down
2 changes: 1 addition & 1 deletion cli/cppcheckexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ int CppCheckExecutor::check_internal(const Settings& settings, Suppressions& sup

returnValue |= cppcheck.analyseWholeProgram(settings.buildDir, mFiles, mFileSettings, stdLogger.getCtuInfo());

if (settings.severity.isEnabled(Severity::information) || settings.checkConfiguration) {
if (settings.checks.isEnabled(Checks::unmatchedSuppression) || settings.checkConfiguration) {
const bool err = reportUnmatchedSuppressions(settings, supprs.nomsg, mFiles, mFileSettings, stdLogger);
if (err && returnValue == 0)
returnValue = settings.exitCode;
Expand Down
2 changes: 1 addition & 1 deletion lib/errortypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ enum class Certainty : std::uint8_t {
};

enum class Checks : std::uint8_t {
unusedFunction, missingInclude, internalCheck
unusedFunction, missingInclude, internalCheck, unmatchedSuppression
};

/** @brief enum class for severity. Used when reporting errors. */
Expand Down
4 changes: 4 additions & 0 deletions lib/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ std::string Settings::parseEnabled(const std::string &str, std::tuple<SimpleEnab
severity.enable(newSeverity);
checks.enable(Checks::missingInclude);
checks.enable(Checks::unusedFunction);
checks.enable(Checks::unmatchedSuppression);
} else if (str == "warning") {
severity.enable(Severity::warning);
} else if (str == "style") {
Expand All @@ -234,10 +235,13 @@ std::string Settings::parseEnabled(const std::string &str, std::tuple<SimpleEnab
severity.enable(Severity::portability);
} else if (str == "information") {
severity.enable(Severity::information);
checks.enable(Checks::unmatchedSuppression); // TODO: deprecated - remove in Cppcheck 2.18
} else if (str == "unusedFunction") {
checks.enable(Checks::unusedFunction);
} else if (str == "missingInclude") {
checks.enable(Checks::missingInclude);
} else if (str == "unmatchedSuppression") {
checks.enable(Checks::unmatchedSuppression);
}
#ifdef CHECK_INTERNAL
else if (str == "internal") {
Expand Down
1 change: 1 addition & 0 deletions releasenotes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ Other:
- Removed deprecated platforms `unix32-unsigned` and `unix64-unsigned`.
- Updated Qt to 6.10.0 (official Windows release only).
- The official Windows binary is now built against Boost 1.89 for increased performance.
- `unmatchedSuppression` has been de-coupled from `information` and needs to be enabled seperately now.
-
61 changes: 57 additions & 4 deletions test/testcmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ class TestCmdlineParser : public TestFixture {
TEST_CASE(disableAll);
TEST_CASE(disableMultiple);
TEST_CASE(disableStylePartial);
TEST_CASE(disableInformationPartial);
TEST_CASE(disableInformationPartial2);
TEST_CASE(disabledMissingIncludeWithInformation2);
TEST_CASE(disabledInformationWithMissingInclude);
TEST_CASE(disableInvalid);
TEST_CASE(disableError);
TEST_CASE(disableEmpty);
Expand Down Expand Up @@ -493,6 +493,11 @@ class TestCmdlineParser : public TestFixture {
TEST_CASE(safetyOverride);
TEST_CASE(noSafety);
TEST_CASE(noSafetyOverride);
TEST_CASE(disabledUnmatchedSuppressionWithInformation);
TEST_CASE(enabledUnmatchedSuppressionWithInformation);
TEST_CASE(enabledUnmatchedSuppressionWithInformationReverseOrder);
TEST_CASE(disabledUnmatchedSuppressionWithInformation2);
TEST_CASE(disabledInformationWithUnmatchedSuppression);

TEST_CASE(ignorepaths1);
TEST_CASE(ignorepaths2);
Expand Down Expand Up @@ -1031,6 +1036,7 @@ class TestCmdlineParser : public TestFixture {
ASSERT(settings->severity.isEnabled(Severity::error));
ASSERT(settings->severity.isEnabled(Severity::information));
ASSERT(!settings->checks.isEnabled(Checks::missingInclude));
ASSERT(settings->checks.isEnabled(Checks::unmatchedSuppression));
}

void enabledUnusedFunction() {
Expand Down Expand Up @@ -1170,7 +1176,7 @@ class TestCmdlineParser : public TestFixture {
ASSERT_EQUALS(false, settings->checks.isEnabled(Checks::internalCheck));
}

void disableInformationPartial() {
void disabledMissingIncludeWithInformation2() {
REDIRECT;
const char * const argv[] = {"cppcheck", "--enable=information", "--disable=missingInclude", "file.cpp"};
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv));
Expand All @@ -1179,7 +1185,7 @@ class TestCmdlineParser : public TestFixture {
ASSERT_EQUALS("", logger->str());
}

void disableInformationPartial2() {
void disabledInformationWithMissingInclude() {
REDIRECT;
const char * const argv[] = {"cppcheck", "--enable=missingInclude", "--disable=information", "file.cpp"};
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv));
Expand Down Expand Up @@ -3421,6 +3427,53 @@ class TestCmdlineParser : public TestFixture {
ASSERT_EQUALS(false, settings->safety);
}

void disabledUnmatchedSuppressionWithInformation() {
REDIRECT;
const char * const argv[] = {"cppcheck", "--disable=unmatchedSuppression", "--enable=information", "file.cpp"};
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv));
ASSERT(settings->severity.isEnabled(Severity::error));
ASSERT(settings->severity.isEnabled(Severity::information));
ASSERT(!settings->checks.isEnabled(Checks::unmatchedSuppression));
ASSERT_EQUALS("", logger->str());
}

void enabledUnmatchedSuppressionWithInformation() {
REDIRECT;
const char * const argv[] = {"cppcheck", "--enable=information", "--enable=unmatchedSuppression", "file.cpp"};
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv));
ASSERT(settings->severity.isEnabled(Severity::error));
ASSERT(settings->severity.isEnabled(Severity::information));
ASSERT(settings->checks.isEnabled(Checks::unmatchedSuppression));
ASSERT_EQUALS("", logger->str());
}

void enabledUnmatchedSuppressionWithInformationReverseOrder() {
REDIRECT;
const char * const argv[] = {"cppcheck", "--enable=unmatchedSuppression", "--enable=information", "file.cpp"};
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv));
ASSERT(settings->severity.isEnabled(Severity::error));
ASSERT(settings->severity.isEnabled(Severity::information));
ASSERT(settings->checks.isEnabled(Checks::unmatchedSuppression));
ASSERT_EQUALS("", logger->str());
}

void disabledUnmatchedSuppressionWithInformation2() {
REDIRECT;
const char * const argv[] = {"cppcheck", "--enable=information", "--disable=unmatchedSuppression", "file.cpp"};
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv));
ASSERT(settings->severity.isEnabled(Severity::information));
ASSERT(!settings->checks.isEnabled(Checks::unmatchedSuppression));
ASSERT_EQUALS("", logger->str());
}

void disabledInformationWithUnmatchedSuppression() {
REDIRECT;
const char * const argv[] = {"cppcheck", "--enable=unmatchedSuppression", "--disable=information", "file.cpp"};
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv));
ASSERT(!settings->severity.isEnabled(Severity::information));
ASSERT(settings->checks.isEnabled(Checks::unmatchedSuppression));
}

void ignorepaths1() {
REDIRECT;
const char * const argv[] = {"cppcheck", "-isrc", "file.cpp"};
Expand Down
6 changes: 3 additions & 3 deletions test/testsuppressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ class TestSuppressions : public TestFixture {
settings.jobs = 1;
settings.quiet = true;
settings.inlineSuppressions = true;
settings.severity.enable(Severity::information);
settings.checks.enable(Checks::unmatchedSuppression);
if (suppression == "unusedFunction")
settings.checks.setEnabled(Checks::unusedFunction, true);
settings.templateFormat = templateFormat;
Expand Down Expand Up @@ -315,7 +315,7 @@ class TestSuppressions : public TestFixture {
$.jobs = 2,
$.quiet = true,
$.inlineSuppressions = true);
settings.severity.enable(Severity::information);
settings.checks.enable(Checks::unmatchedSuppression);
settings.templateFormat = templateFormat;

Suppressions supprs;
Expand Down Expand Up @@ -364,7 +364,7 @@ class TestSuppressions : public TestFixture {
$.jobs = 2,
$.quiet = true,
$.inlineSuppressions = true);
settings.severity.enable(Severity::information);
settings.checks.enable(Checks::unmatchedSuppression);
settings.templateFormat = templateFormat;

Suppressions supprs;
Expand Down