From 1961d6d0f74c6a03d6786920e08635e7476493a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 28 May 2017 20:34:58 +0200 Subject: [PATCH] CppCheck: make sure preprocessor syntax errors are reported --- lib/cppcheck.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 265f11e5c..2351b228b 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -144,6 +144,25 @@ unsigned int CppCheck::processFile(const std::string& filename, const std::strin simplecpp::OutputList outputList; std::vector files; 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 callstack; + callstack.push_back(loc1); + + ErrorLogger::ErrorMessage errmsg(callstack, + "", + Severity::error, + it->msg, + "syntaxError", + false); + _errorLogger.reportErr(errmsg); + return 1; + } + preprocessor.loadFiles(tokens1, files); if (!_settings.plistOutput.empty()) {