Fixed #5661 (--suppress=missingInclude has no effect)

This commit is contained in:
Daniel Marjamäki 2014-05-03 19:31:15 +02:00
parent 3bdfad0b73
commit 1903d95015
4 changed files with 37 additions and 20 deletions

View File

@ -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<ErrorLogger::ErrorMessage::FileLocation> 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);
}

View File

@ -34,6 +34,7 @@
#include <stack>
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<ErrorLogger::ErrorMessage::FileLocation> 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<ErrorLogger::ErrorMessage::FileLocation> 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);
}
}

View File

@ -57,6 +57,7 @@ public:
Preprocessor(Settings *settings = nullptr, ErrorLogger *errorLogger = nullptr);
static bool missingIncludeFlag;
static bool missingSystemIncludeFlag;
/**
* Extract the code for each configuration

View File

@ -3568,6 +3568,13 @@ private:
settings.nomsg.addSuppression("missingIncludeSystem");
preprocessor.handleIncludes(code,"test.c",includePaths,defs,pragmaOnce,std::list<std::string>());
ASSERT_EQUALS("", errout.str());
pragmaOnce.clear();
errout.str("");
settings = Settings();
settings.nomsg.addSuppression("missingInclude");
preprocessor.handleIncludes(code,"test.c",includePaths,defs,pragmaOnce,std::list<std::string>());
ASSERT_EQUALS("", errout.str());
}
// #3285 - #elif