From 1903d950157153072b9fb21b709a2cff4a85141e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 3 May 2014 19:31:15 +0200 Subject: [PATCH] Fixed #5661 (--suppress=missingInclude has no effect) --- cli/cppcheckexecutor.cpp | 5 +++-- lib/preprocessor.cpp | 44 +++++++++++++++++++++++---------------- lib/preprocessor.h | 1 + test/testpreprocessor.cpp | 7 +++++++ 4 files changed, 37 insertions(+), 20 deletions(-) diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index b947fea01..2fb4c1380 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -163,6 +163,7 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c int CppCheckExecutor::check(int argc, const char* const argv[]) { Preprocessor::missingIncludeFlag = false; + Preprocessor::missingSystemIncludeFlag = false; CppCheck cppCheck(*this, true); @@ -469,7 +470,7 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck, int /*argc*/, const cha if (!settings.checkConfiguration) { cppcheck.tooManyConfigsError("",0U); - if (settings.isEnabled("missingInclude") && Preprocessor::missingIncludeFlag) { + if (settings.isEnabled("missingInclude") && (Preprocessor::missingIncludeFlag || Preprocessor::missingSystemIncludeFlag)) { const std::list callStack; ErrorLogger::ErrorMessage msg(callStack, Severity::information, @@ -479,7 +480,7 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck, int /*argc*/, const cha "files are found. Please check your project's include directories and add all of them " "as include directories for Cppcheck. To see what files Cppcheck cannot find use " "--check-config.", - "missingInclude", + Preprocessor::missingIncludeFlag ? "missingInclude" : "missingIncludeSystem", false); reportInfo(msg); } diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 6f491e51b..f91be3d17 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -34,6 +34,7 @@ #include bool Preprocessor::missingIncludeFlag; +bool Preprocessor::missingSystemIncludeFlag; char Preprocessor::macroChar = char(1); @@ -2365,26 +2366,33 @@ void Preprocessor::handleIncludes(std::string &code, const std::string &filePath // Report that include is missing void Preprocessor::missingInclude(const std::string &filename, unsigned int linenr, const std::string &header, HeaderTypes headerType) { - const std::string msgtype = (headerType==SystemHeader)?"missingIncludeSystem":"missingInclude"; - if (!_settings->nomsg.isSuppressed(msgtype, Path::fromNativeSeparators(filename), linenr)) { - missingIncludeFlag = true; - if (_errorLogger && _settings->checkConfiguration) { + const std::string fname = Path::fromNativeSeparators(filename); + if (_settings->nomsg.isSuppressed("missingInclude", fname, linenr)) + return; + if (headerType == SystemHeader && _settings->nomsg.isSuppressed("missingIncludeSystem", fname, linenr)) + return; - std::list locationList; - if (!filename.empty()) { - ErrorLogger::ErrorMessage::FileLocation loc; - loc.line = linenr; - loc.setfile(Path::toNativeSeparators(filename)); - locationList.push_back(loc); - } - ErrorLogger::ErrorMessage errmsg(locationList, Severity::information, - (headerType==SystemHeader) ? - "Include file: <" + header + "> not found. Please note: Cppcheck does not need standard library headers to get proper results." : - "Include file: \"" + header + "\" not found.", - msgtype, false); - errmsg.file0 = file0; - _errorLogger->reportInfo(errmsg); + if (headerType == SystemHeader) + missingSystemIncludeFlag = true; + else + missingIncludeFlag = true; + if (_errorLogger && _settings->checkConfiguration) { + + std::list locationList; + if (!filename.empty()) { + ErrorLogger::ErrorMessage::FileLocation loc; + loc.line = linenr; + loc.setfile(Path::toNativeSeparators(filename)); + locationList.push_back(loc); } + ErrorLogger::ErrorMessage errmsg(locationList, Severity::information, + (headerType==SystemHeader) ? + "Include file: <" + header + "> not found. Please note: Cppcheck does not need standard library headers to get proper results." : + "Include file: \"" + header + "\" not found.", + (headerType==SystemHeader) ? "missingIncludeSystem" : "missingInclude", + false); + errmsg.file0 = file0; + _errorLogger->reportInfo(errmsg); } } diff --git a/lib/preprocessor.h b/lib/preprocessor.h index 1e161545f..e75ab2460 100644 --- a/lib/preprocessor.h +++ b/lib/preprocessor.h @@ -57,6 +57,7 @@ public: Preprocessor(Settings *settings = nullptr, ErrorLogger *errorLogger = nullptr); static bool missingIncludeFlag; + static bool missingSystemIncludeFlag; /** * Extract the code for each configuration diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index c606bb53a..e0f32b3d8 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -3568,6 +3568,13 @@ private: settings.nomsg.addSuppression("missingIncludeSystem"); preprocessor.handleIncludes(code,"test.c",includePaths,defs,pragmaOnce,std::list()); ASSERT_EQUALS("", errout.str()); + + pragmaOnce.clear(); + errout.str(""); + settings = Settings(); + settings.nomsg.addSuppression("missingInclude"); + preprocessor.handleIncludes(code,"test.c",includePaths,defs,pragmaOnce,std::list()); + ASSERT_EQUALS("", errout.str()); } // #3285 - #elif