diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 238073dd0..1c72c0c7b 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -586,7 +586,7 @@ void CppCheck::reportErr(const ErrorLogger::ErrorMessage &msg) return; } - if (!_settings.nofail.isSuppressed(msg._id, file, line)) + if (!_settings.nofail.isSuppressed(msg._id, file, line) && !_settings.nomsg.isSuppressed(msg._id, file, line)) exitcode = 1; _errorList.push_back(errmsg); diff --git a/test/testsuppressions.cpp b/test/testsuppressions.cpp index c3d45439a..525c18e68 100644 --- a/test/testsuppressions.cpp +++ b/test/testsuppressions.cpp @@ -131,15 +131,15 @@ private: } // Check the suppression - void checkSuppression(const char code[], const std::string &suppression = emptyString) { + unsigned int checkSuppression(const char code[], const std::string &suppression = emptyString) { std::map files; files["test.cpp"] = code; - checkSuppression(files, suppression); + return checkSuppression(files, suppression); } // Check the suppression for multiple files - void checkSuppression(std::map &files, const std::string &suppression = emptyString) { + unsigned int checkSuppression(std::map &files, const std::string &suppression = emptyString) { // Clear the error log errout.str(""); @@ -153,15 +153,18 @@ private: ASSERT_EQUALS("", r); } + unsigned int exitCode = 0; for (std::map::const_iterator file = files.begin(); file != files.end(); ++file) { - cppCheck.check(file->first, file->second); + exitCode |= cppCheck.check(file->first, file->second); } cppCheck.analyseWholeProgram(); reportSuppressions(settings, files); + + return exitCode; } - void checkSuppressionThreads(const char code[], const std::string &suppression = emptyString) { + unsigned int checkSuppressionThreads(const char code[], const std::string &suppression = emptyString) { errout.str(""); output.str(""); @@ -179,16 +182,18 @@ private: for (std::map::const_iterator i = files.begin(); i != files.end(); ++i) executor.addFileContent(i->first, code); - executor.check(); + unsigned int exitCode = executor.check(); std::map files_for_report; for (std::map::const_iterator file = files.begin(); file != files.end(); ++file) files_for_report[file->first] = ""; reportSuppressions(settings, files_for_report); + + return exitCode; } - void runChecks(void (TestSuppressions::*check)(const char[], const std::string &)) { + void runChecks(unsigned int (TestSuppressions::*check)(const char[], const std::string &)) { // check to make sure the appropriate error is present (this->*check)("void f() {\n" " int a;\n" @@ -319,6 +324,18 @@ private: "}\n", ""); ASSERT_EQUALS("[test.cpp:4]: (information) Unmatched suppression: uninitvar\n", errout.str()); + + // #5746 - exitcode + ASSERT_EQUALS(1U, + (this->*check)("int f() {\n" + " int a; return a;\n" + "}\n", + "")); + ASSERT_EQUALS(0U, + (this->*check)("int f() {\n" + " int a; return a;\n" + "}\n", + "uninitvar")); } void suppressionsSettings() {