diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index c6cb977e1a86..dce52fdefa6b 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -542,15 +542,21 @@ unsigned int CppCheck::checkClang(const std::string &path) return mExitCode; } +static ErrorMessage makeError(const std::string &filename, int line, unsigned int column, const std::string &msg, const std::string &id) +{ + const ErrorMessage::FileLocation loc1(filename, line, column); + std::list callstack(1, loc1); + + return ErrorMessage(callstack, + emptyString, + Severity::error, + msg, + id, + Certainty::normal); +} + unsigned int CppCheck::check(const std::string &path) { - if (!Path::isFile(path)) { - std::string fixedpath = Path::simplifyPath(path); - fixedpath = Path::toNativeSeparators(fixedpath); - const std::string errorMsg("File " + fixedpath + " does not exists. Skipping file."); - fileNotFoundError(Path::simplifyPath(path), errorMsg); - return 0; - } if (mSettings.clang) return checkClang(path); @@ -565,13 +571,6 @@ unsigned int CppCheck::check(const std::string &path, const std::string &content unsigned int CppCheck::check(const FileSettings &fs) { - if (!Path::isFile(fs.filename)) { - std::string fixedpath = Path::simplifyPath(fs.filename); - fixedpath = Path::toNativeSeparators(fixedpath); - const std::string errorMsg("File " + fixedpath + " does not exists. Skipping file."); - fileNotFoundError(fs.filename, errorMsg); - return 0; - } CppCheck temp(mErrorLogger, mUseGlobalSuppressions, mExecuteCommand); temp.mSettings = mSettings; if (!temp.mSettings.userDefines.empty()) @@ -684,7 +683,14 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string output.msg, "syntaxError", Certainty::normal); - reportErr(errmsg); + if(output.type == simplecpp::Output::Type::FILE_NOT_FOUND){ + const std::string fixedpath = Path::toNativeSeparators(file); + const std::string errorMsg("File " + fixedpath + " does not exists. Skipping file."); + fileNotFoundError(file, errorMsg); + } + else{ + reportErr(makeError(file, output.location.line, output.location.col, output.msg, "syntaxError")); + } return mExitCode; } @@ -1047,28 +1053,15 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string return mExitCode; } -static ErrorMessage makeError(const std::string &filename, const std::string &msg, const std::string &id) -{ - const ErrorMessage::FileLocation loc1(filename, 0, 0); - std::list callstack(1, loc1); - - return ErrorMessage(callstack, - emptyString, - Severity::error, - msg, - id, - Certainty::normal); -} - // TODO: replace with ErrorMessage::fromInternalError() void CppCheck::internalError(const std::string &filename, const std::string &msg) { - mErrorLogger.reportErr(makeError(filename, "Bailing out from analysis:" + msg, "internalError")); + mErrorLogger.reportErr(makeError(filename, 0, 0U, "Bailing out from analysis:" + msg, "internalError")); } void CppCheck::fileNotFoundError(const std::string &filename, const std::string &msg) { - mErrorLogger.reportErr(makeError(filename, msg, "fileNotFound")); + mErrorLogger.reportErr(makeError(filename, 0, 0U, msg, "fileNotFound")); } //--------------------------------------------------------------------------- diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 71014e717fb1..479f1328e18a 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -752,6 +752,7 @@ bool Preprocessor::hasErrors(const simplecpp::Output &output) case simplecpp::Output::SYNTAX_ERROR: case simplecpp::Output::UNHANDLED_CHAR_ERROR: case simplecpp::Output::EXPLICIT_INCLUDE_NOT_FOUND: + case simplecpp::Output::FILE_NOT_FOUND: return true; case simplecpp::Output::WARNING: case simplecpp::Output::MISSING_HEADER: