diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index f2dabc3a6..e29d5d79f 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -160,6 +160,10 @@ unsigned int CppCheck::processFile(const std::string& filename, const std::strin preprocessor.preprocess(fin, filedata, configurations, filename, _settings._includePaths); } + // Unhandled chars found during preprocessing => abort checking this file + if (preprocessor.foundUnhandledChars()) + return 0; + if (_settings.checkConfiguration) { return 0; } diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index f91be3d17..1a4d37055 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -38,7 +38,7 @@ bool Preprocessor::missingSystemIncludeFlag; char Preprocessor::macroChar = char(1); -Preprocessor::Preprocessor(Settings *settings, ErrorLogger *errorLogger) : _settings(settings), _errorLogger(errorLogger) +Preprocessor::Preprocessor(Settings *settings, ErrorLogger *errorLogger) : _settings(settings), _errorLogger(errorLogger), _foundUnhandledChars(false) { } @@ -486,6 +486,7 @@ std::string Preprocessor::removeComments(const std::string &str, const std::stri << "Neither unicode nor extended ASCII are supported. " << "(line=" << lineno << ", character code=" << std::hex << (int(ch) & 0xff) << ")"; writeError(filename, lineno, _errorLogger, "syntaxError", errmsg.str()); + _foundUnhandledChars = true; } if (_settings && _settings->terminated()) diff --git a/lib/preprocessor.h b/lib/preprocessor.h index e75ab2460..9796ef18c 100644 --- a/lib/preprocessor.h +++ b/lib/preprocessor.h @@ -251,6 +251,10 @@ public: file0 = f; } + bool foundUnhandledChars() const { + return _foundUnhandledChars; + } + private: void missingInclude(const std::string &filename, unsigned int linenr, const std::string &header, HeaderTypes headerType); @@ -274,6 +278,11 @@ private: /** filename for cpp/c file - useful when reporting errors */ std::string file0; + + /** set to true if unhandled chars are found in code. any char is ok + * in comments and string literals, but variable/type names must + * have plain ascii characters. */ + bool _foundUnhandledChars; }; /// @}