Skip to content

Commit a1dcb3f

Browse files
committed
fixed #10697 - split unmatchedSuppression from --enable=information [skip ci]
1 parent 98b6ff5 commit a1dcb3f

6 files changed

Lines changed: 77 additions & 9 deletions

File tree

cli/cmdlineparser.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,8 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
425425
};
426426

427427
bool executorAuto = true;
428+
bool enableInformation = false;
429+
bool enableUnmatchedSuppression = false;
428430

429431
for (int i = 1; i < argc; i++) {
430432
if (argv[i][0] != '-') {
@@ -694,6 +696,12 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
694696
mSettings.addEnabled("performance");
695697
mSettings.addEnabled("portability");
696698
}
699+
if (enable_arg.find("information") != std::string::npos) {
700+
enableInformation = true;
701+
}
702+
if (enable_arg.find("unmatchedSuppression") != std::string::npos) {
703+
enableUnmatchedSuppression = true;
704+
}
697705
}
698706

699707
// --error-exitcode=1
@@ -1575,6 +1583,9 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
15751583
}
15761584
}
15771585

1586+
if (enableInformation && !enableUnmatchedSuppression)
1587+
mLogger.printMessage("unmatchedSuppression is no longer included in --enable=information starting with Cppcheck 2.18. Please use --enable=unmatchedSuppression instead.");
1588+
15781589
// TODO: bail out?
15791590
if (!executorAuto && mSettings.useSingleJob())
15801591
mLogger.printMessage("'--executor' has no effect as only a single job will be used.");

cli/cppcheckexecutor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ int CppCheckExecutor::check_internal(const Settings& settings, Suppressions& sup
413413

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

416-
if (settings.severity.isEnabled(Severity::information) || settings.checkConfiguration) {
416+
if (settings.checks.isEnabled(Checks::unmatchedSuppression) || settings.checkConfiguration) {
417417
const bool err = reportUnmatchedSuppressions(settings, supprs.nomsg, mFiles, mFileSettings, stdLogger);
418418
if (err && returnValue == 0)
419419
returnValue = settings.exitCode;

lib/errortypes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ enum class Certainty : std::uint8_t {
5757
};
5858

5959
enum class Checks : std::uint8_t {
60-
unusedFunction, missingInclude, internalCheck
60+
unusedFunction, missingInclude, internalCheck, unmatchedSuppression
6161
};
6262

6363
/** @brief enum class for severity. Used when reporting errors. */

lib/settings.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ std::string Settings::parseEnabled(const std::string &str, std::tuple<SimpleEnab
224224
severity.enable(newSeverity);
225225
checks.enable(Checks::missingInclude);
226226
checks.enable(Checks::unusedFunction);
227+
checks.enable(Checks::unmatchedSuppression);
227228
} else if (str == "warning") {
228229
severity.enable(Severity::warning);
229230
} else if (str == "style") {
@@ -234,10 +235,13 @@ std::string Settings::parseEnabled(const std::string &str, std::tuple<SimpleEnab
234235
severity.enable(Severity::portability);
235236
} else if (str == "information") {
236237
severity.enable(Severity::information);
238+
checks.enable(Checks::unmatchedSuppression); // TODO: deprecated - remove in Cppcheck 2.18
237239
} else if (str == "unusedFunction") {
238240
checks.enable(Checks::unusedFunction);
239241
} else if (str == "missingInclude") {
240242
checks.enable(Checks::missingInclude);
243+
} else if (str == "unmatchedSuppression") {
244+
checks.enable(Checks::unmatchedSuppression);
241245
}
242246
#ifdef CHECK_INTERNAL
243247
else if (str == "internal") {

test/testcmdlineparser.cpp

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ class TestCmdlineParser : public TestFixture {
205205
TEST_CASE(disableAll);
206206
TEST_CASE(disableMultiple);
207207
TEST_CASE(disableStylePartial);
208-
TEST_CASE(disableInformationPartial);
209-
TEST_CASE(disableInformationPartial2);
208+
TEST_CASE(disabledMissingIncludeWithInformation2);
209+
TEST_CASE(disabledInformationWithMissingInclude);
210210
TEST_CASE(disableInvalid);
211211
TEST_CASE(disableError);
212212
TEST_CASE(disableEmpty);
@@ -493,6 +493,11 @@ class TestCmdlineParser : public TestFixture {
493493
TEST_CASE(safetyOverride);
494494
TEST_CASE(noSafety);
495495
TEST_CASE(noSafetyOverride);
496+
TEST_CASE(disabledUnmatchedSuppressionWithInformation);
497+
TEST_CASE(enabledUnmatchedSuppressionWithInformation);
498+
TEST_CASE(enabledUnmatchedSuppressionWithInformationReverseOrder);
499+
TEST_CASE(disabledUnmatchedSuppressionWithInformation2);
500+
TEST_CASE(disabledInformationWithUnmatchedSuppression);
496501

497502
TEST_CASE(ignorepaths1);
498503
TEST_CASE(ignorepaths2);
@@ -1031,6 +1036,7 @@ class TestCmdlineParser : public TestFixture {
10311036
ASSERT(settings->severity.isEnabled(Severity::error));
10321037
ASSERT(settings->severity.isEnabled(Severity::information));
10331038
ASSERT(!settings->checks.isEnabled(Checks::missingInclude));
1039+
ASSERT(settings->checks.isEnabled(Checks::unmatchedSuppression));
10341040
}
10351041

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

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

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

3430+
void disabledUnmatchedSuppressionWithInformation() {
3431+
REDIRECT;
3432+
const char * const argv[] = {"cppcheck", "--disable=unmatchedSuppression", "--enable=information", "file.cpp"};
3433+
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv));
3434+
ASSERT(settings->severity.isEnabled(Severity::error));
3435+
ASSERT(settings->severity.isEnabled(Severity::information));
3436+
ASSERT(!settings->checks.isEnabled(Checks::unmatchedSuppression));
3437+
ASSERT_EQUALS("", logger->str());
3438+
}
3439+
3440+
void enabledUnmatchedSuppressionWithInformation() {
3441+
REDIRECT;
3442+
const char * const argv[] = {"cppcheck", "--enable=information", "--enable=unmatchedSuppression", "file.cpp"};
3443+
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv));
3444+
ASSERT(settings->severity.isEnabled(Severity::error));
3445+
ASSERT(settings->severity.isEnabled(Severity::information));
3446+
ASSERT(settings->checks.isEnabled(Checks::unmatchedSuppression));
3447+
ASSERT_EQUALS("", logger->str());
3448+
}
3449+
3450+
void enabledUnmatchedSuppressionWithInformationReverseOrder() {
3451+
REDIRECT;
3452+
const char * const argv[] = {"cppcheck", "--enable=unmatchedSuppression", "--enable=information", "file.cpp"};
3453+
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv));
3454+
ASSERT(settings->severity.isEnabled(Severity::error));
3455+
ASSERT(settings->severity.isEnabled(Severity::information));
3456+
ASSERT(settings->checks.isEnabled(Checks::unmatchedSuppression));
3457+
ASSERT_EQUALS("", logger->str());
3458+
}
3459+
3460+
void disabledUnmatchedSuppressionWithInformation2() {
3461+
REDIRECT;
3462+
const char * const argv[] = {"cppcheck", "--enable=information", "--disable=unmatchedSuppression", "file.cpp"};
3463+
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv));
3464+
ASSERT(settings->severity.isEnabled(Severity::information));
3465+
ASSERT(!settings->checks.isEnabled(Checks::unmatchedSuppression));
3466+
ASSERT_EQUALS("", logger->str());
3467+
}
3468+
3469+
void disabledInformationWithUnmatchedSuppression() {
3470+
REDIRECT;
3471+
const char * const argv[] = {"cppcheck", "--enable=unmatchedSuppression", "--disable=information", "file.cpp"};
3472+
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv));
3473+
ASSERT(!settings->severity.isEnabled(Severity::information));
3474+
ASSERT(settings->checks.isEnabled(Checks::unmatchedSuppression));
3475+
}
3476+
34243477
void ignorepaths1() {
34253478
REDIRECT;
34263479
const char * const argv[] = {"cppcheck", "-isrc", "file.cpp"};

test/testsuppressions.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ class TestSuppressions : public TestFixture {
269269
settings.jobs = 1;
270270
settings.quiet = true;
271271
settings.inlineSuppressions = true;
272-
settings.severity.enable(Severity::information);
272+
settings.checks.enable(Checks::unmatchedSuppression);
273273
if (suppression == "unusedFunction")
274274
settings.checks.setEnabled(Checks::unusedFunction, true);
275275
settings.templateFormat = templateFormat;
@@ -315,7 +315,7 @@ class TestSuppressions : public TestFixture {
315315
$.jobs = 2,
316316
$.quiet = true,
317317
$.inlineSuppressions = true);
318-
settings.severity.enable(Severity::information);
318+
settings.checks.enable(Checks::unmatchedSuppression);
319319
settings.templateFormat = templateFormat;
320320

321321
Suppressions supprs;
@@ -364,7 +364,7 @@ class TestSuppressions : public TestFixture {
364364
$.jobs = 2,
365365
$.quiet = true,
366366
$.inlineSuppressions = true);
367-
settings.severity.enable(Severity::information);
367+
settings.checks.enable(Checks::unmatchedSuppression);
368368
settings.templateFormat = templateFormat;
369369

370370
Suppressions supprs;

0 commit comments

Comments
 (0)