CppCheck: make sure preprocessor syntax errors are reported

This commit is contained in:
Daniel Marjamäki 2017-05-28 20:34:58 +02:00
parent 956b5812e7
commit 1961d6d0f7
1 changed files with 19 additions and 0 deletions

View File

@ -144,6 +144,25 @@ unsigned int CppCheck::processFile(const std::string& filename, const std::strin
simplecpp::OutputList outputList; simplecpp::OutputList outputList;
std::vector<std::string> files; std::vector<std::string> files;
simplecpp::TokenList tokens1(fileStream, files, filename, &outputList); simplecpp::TokenList tokens1(fileStream, files, filename, &outputList);
// If there is a syntax error, report it and stop
for (simplecpp::OutputList::const_iterator it = outputList.begin(); it != outputList.end(); ++it) {
if (it->type != simplecpp::Output::SYNTAX_ERROR)
continue;
const ErrorLogger::ErrorMessage::FileLocation loc1(it->location.file(), it->location.line);
std::list<ErrorLogger::ErrorMessage::FileLocation> callstack;
callstack.push_back(loc1);
ErrorLogger::ErrorMessage errmsg(callstack,
"",
Severity::error,
it->msg,
"syntaxError",
false);
_errorLogger.reportErr(errmsg);
return 1;
}
preprocessor.loadFiles(tokens1, files); preprocessor.loadFiles(tokens1, files);
if (!_settings.plistOutput.empty()) { if (!_settings.plistOutput.empty()) {