From 1a7595e29b360b228df6bdb62927ec31dbbbe15b Mon Sep 17 00:00:00 2001 From: PKEuS Date: Thu, 18 Feb 2021 22:35:55 +0100 Subject: [PATCH] Bugfix: Apply --relative-paths also to preprocessor errors Merged from LCppC --- lib/cppcheck.cpp | 6 +++++- lib/preprocessor.cpp | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 1f2fb5997..10e2ff233 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -574,7 +574,11 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string } if (err) { - const ErrorMessage::FileLocation loc1(output.location.file(), output.location.line, output.location.col); + std::string file = Path::fromNativeSeparators(output.location.file()); + if (mSettings.relativePaths) + file = Path::getRelativePath(file, mSettings.basePaths); + + const ErrorMessage::FileLocation loc1(file, output.location.line, output.location.col); std::list callstack(1, loc1); ErrorMessage errmsg(callstack, diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index a8bc0719c..8e378f473 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -810,7 +810,11 @@ void Preprocessor::error(const std::string &filename, unsigned int linenr, const { std::list locationList; if (!filename.empty()) { - const ErrorMessage::FileLocation loc(filename, linenr, 0); + std::string file = Path::fromNativeSeparators(filename); + if (mSettings.relativePaths) + file = Path::getRelativePath(file, mSettings.basePaths); + + const ErrorMessage::FileLocation loc(file, linenr, 0); locationList.push_back(loc); } mErrorLogger->reportErr(ErrorMessage(locationList,