Skip to content
Merged
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
16 changes: 14 additions & 2 deletions lib/preprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ void Preprocessor::inlineSuppressions(SuppressionList &suppressions)
::addInlineSuppressions(filedata->tokens, mSettings, suppressions, err);
}
for (const BadInlineSuppression &bad : err) {
error(bad.file, bad.line, bad.col, bad.errmsg, simplecpp::Output::ERROR); // TODO: use individual (non-fatal) ID
invalidSuppression(bad.file, bad.line, bad.col, bad.errmsg); // TODO: column is always 0
}
}

Expand Down Expand Up @@ -914,6 +914,11 @@ static std::string simplecppErrToId(simplecpp::Output::Type type)
}

void Preprocessor::error(const std::string &filename, unsigned int linenr, unsigned int col, const std::string &msg, simplecpp::Output::Type type)
{
error(filename, linenr, col, msg, simplecppErrToId(type));
}

void Preprocessor::error(const std::string &filename, unsigned int linenr, unsigned int col, const std::string &msg, const std::string& id)
{
std::list<ErrorMessage::FileLocation> locationList;
if (!filename.empty()) {
Expand All @@ -927,7 +932,7 @@ void Preprocessor::error(const std::string &filename, unsigned int linenr, unsig
mFile0,
Severity::error,
msg,
simplecppErrToId(type),
id,
Certainty::normal));
}

Expand All @@ -939,6 +944,7 @@ void Preprocessor::missingInclude(const std::string &filename, unsigned int line

std::list<ErrorMessage::FileLocation> locationList;
if (!filename.empty()) {
// TODO: add relative path handling?
locationList.emplace_back(filename, linenr, col);
}
ErrorMessage errmsg(std::move(locationList), mFile0, Severity::information,
Expand All @@ -950,6 +956,11 @@ void Preprocessor::missingInclude(const std::string &filename, unsigned int line
mErrorLogger.reportErr(errmsg);
}

void Preprocessor::invalidSuppression(const std::string &filename, unsigned int linenr, unsigned int col, const std::string &msg)
{
error(filename, linenr, col, msg, "invalidSuppression");
}

void Preprocessor::getErrorMessages(ErrorLogger &errorLogger, const Settings &settings)
{
std::vector<std::string> files;
Expand All @@ -962,6 +973,7 @@ void Preprocessor::getErrorMessages(ErrorLogger &errorLogger, const Settings &se
preprocessor.error("", 1, 2, "message", simplecpp::Output::UNHANDLED_CHAR_ERROR);
preprocessor.error("", 1, 2, "message", simplecpp::Output::INCLUDE_NESTED_TOO_DEEPLY);
preprocessor.error("", 1, 2, "message", simplecpp::Output::FILE_NOT_FOUND);
preprocessor.invalidSuppression("", 1, 2, "message");
}

void Preprocessor::dump(std::ostream &out) const
Expand Down
2 changes: 2 additions & 0 deletions lib/preprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ class CPPCHECKLIB WARN_UNUSED Preprocessor {
};

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

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

Expand Down
8 changes: 4 additions & 4 deletions test/testsuppressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ class TestSuppressions : public TestFixture {
" a++;\n"
"}\n",
""));
ASSERT_EQUALS("[test.cpp:2:0]: (error) File suppression should be at the top of the file [preprocessorErrorDirective]\n"
ASSERT_EQUALS("[test.cpp:2:0]: (error) File suppression should be at the top of the file [invalidSuppression]\n"
"[test.cpp:4:5]: (error) Uninitialized variable: a [uninitvar]\n", errout_str());

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

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

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

Expand Down
Loading