Skip to content

Commit 33d0fcd

Browse files
committed
added separate (non-critical) error ID for invalid inline suppressions [skip ci]
1 parent 657b7c5 commit 33d0fcd

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

lib/preprocessor.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ void Preprocessor::inlineSuppressions(SuppressionList &suppressions)
307307
::addInlineSuppressions(filedata->tokens, mSettings, suppressions, err);
308308
}
309309
for (const BadInlineSuppression &bad : err) {
310-
error(bad.file, bad.line, bad.col, bad.errmsg, simplecpp::Output::ERROR); // TODO: use individual (non-fatal) ID
310+
invalidSuppression(bad.file, bad.line, bad.col, bad.errmsg); // TODO: column is always 0
311311
}
312312
}
313313

@@ -956,6 +956,11 @@ void Preprocessor::missingInclude(const std::string &filename, unsigned int line
956956
mErrorLogger.reportErr(errmsg);
957957
}
958958

959+
void Preprocessor::invalidSuppression(const std::string &filename, unsigned int linenr, unsigned int col, const std::string &msg)
960+
{
961+
error(filename, linenr, col, msg, "invalidSuppression");
962+
}
963+
959964
void Preprocessor::getErrorMessages(ErrorLogger &errorLogger, const Settings &settings)
960965
{
961966
std::vector<std::string> files;
@@ -968,6 +973,7 @@ void Preprocessor::getErrorMessages(ErrorLogger &errorLogger, const Settings &se
968973
preprocessor.error("", 1, 2, "message", simplecpp::Output::UNHANDLED_CHAR_ERROR);
969974
preprocessor.error("", 1, 2, "message", simplecpp::Output::INCLUDE_NESTED_TOO_DEEPLY);
970975
preprocessor.error("", 1, 2, "message", simplecpp::Output::FILE_NOT_FOUND);
976+
preprocessor.invalidSuppression("", 1, 2, "message");
971977
}
972978

973979
void Preprocessor::dump(std::ostream &out) const

lib/preprocessor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ class CPPCHECKLIB WARN_UNUSED Preprocessor {
159159
};
160160

161161
void missingInclude(const std::string &filename, unsigned int linenr, unsigned int col, const std::string &header, HeaderTypes headerType);
162+
void invalidSuppression(const std::string &filename, unsigned int linenr, unsigned int col, const std::string &msg);
162163
void error(const std::string &filename, unsigned int linenr, unsigned int col, const std::string &msg, const std::string& id);
163164

164165
void addRemarkComments(const simplecpp::TokenList &tokens, std::vector<RemarkComment> &remarkComments) const;

test/testsuppressions.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ class TestSuppressions : public TestFixture {
426426
" a++;\n"
427427
"}\n",
428428
""));
429-
ASSERT_EQUALS("[test.cpp:2:0]: (error) File suppression should be at the top of the file [preprocessorErrorDirective]\n"
429+
ASSERT_EQUALS("[test.cpp:2:0]: (error) File suppression should be at the top of the file [invalidSuppression]\n"
430430
"[test.cpp:4:5]: (error) Uninitialized variable: a [uninitvar]\n", errout_str());
431431

432432
ASSERT_EQUALS(1, (this->*check)("void f() {\n"
@@ -435,7 +435,7 @@ class TestSuppressions : public TestFixture {
435435
"}\n"
436436
"// cppcheck-suppress-file uninitvar\n",
437437
""));
438-
ASSERT_EQUALS("[test.cpp:5:0]: (error) File suppression should be at the top of the file [preprocessorErrorDirective]\n"
438+
ASSERT_EQUALS("[test.cpp:5:0]: (error) File suppression should be at the top of the file [invalidSuppression]\n"
439439
"[test.cpp:3:5]: (error) Uninitialized variable: a [uninitvar]\n", errout_str());
440440

441441
ASSERT_EQUALS(0, (this->*check)("// cppcheck-suppress-file uninitvar\n"
@@ -687,7 +687,7 @@ class TestSuppressions : public TestFixture {
687687
" b++;\n"
688688
"}\n",
689689
""));
690-
ASSERT_EQUALS("[test.cpp:2:0]: (error) Suppress Begin: No matching end [preprocessorErrorDirective]\n"
690+
ASSERT_EQUALS("[test.cpp:2:0]: (error) Suppress Begin: No matching end [invalidSuppression]\n"
691691
"[test.cpp:4:5]: (error) Uninitialized variable: a [uninitvar]\n"
692692
"[test.cpp:6:5]: (error) Uninitialized variable: b [uninitvar]\n", errout_str());
693693

@@ -699,7 +699,7 @@ class TestSuppressions : public TestFixture {
699699
" // cppcheck-suppress-end uninitvar\n"
700700
"}\n",
701701
""));
702-
ASSERT_EQUALS("[test.cpp:6:0]: (error) Suppress End: No matching begin [preprocessorErrorDirective]\n"
702+
ASSERT_EQUALS("[test.cpp:6:0]: (error) Suppress End: No matching begin [invalidSuppression]\n"
703703
"[test.cpp:3:5]: (error) Uninitialized variable: a [uninitvar]\n"
704704
"[test.cpp:5:5]: (error) Uninitialized variable: b [uninitvar]\n", errout_str());
705705

0 commit comments

Comments
 (0)