Fixed #3275 (Missing includes always reported)

This commit is contained in:
Daniel Marjamäki 2011-11-06 08:59:07 +01:00
parent e11c1f7975
commit ed97b62610
3 changed files with 21 additions and 1 deletions

View File

@ -205,7 +205,7 @@ int CppCheckExecutor::check(int argc, const char* const argv[])
if (!_settings._errorsOnly)
reportUnmatchedSuppressions(cppCheck.settings().nomsg.getUnmatchedGlobalSuppressions());
if (Preprocessor::missingIncludeFlag) {
if (_settings.isEnabled("missingInclude") && Preprocessor::missingIncludeFlag) {
const std::list<ErrorLogger::ErrorMessage::FileLocation> callStack;
ErrorLogger::ErrorMessage msg(callStack,
Severity::information,

View File

@ -99,6 +99,9 @@ std::string Settings::addEnabled(const std::string &str)
}
} else if (id.find(str) != id.end()) {
_enabled.insert(str);
if (str == "information") {
_enabled.insert("missingInclude");
}
} else if (!handled) {
if (str.empty())
return std::string("cppcheck: --enable parameter is empty");

View File

@ -216,6 +216,9 @@ private:
TEST_CASE(invalid_define); // #2605 - hang for: '#define ='
// Show 'missing include' warnings
TEST_CASE(missingInclude);
// inline suppression, missingInclude
TEST_CASE(inline_suppression_for_missing_include);
@ -2756,6 +2759,20 @@ private:
preprocessor.preprocess(src, processedFile, cfg, "", paths); // don't hang
}
void missingInclude() {
Settings settings;
Preprocessor preprocessor(&settings, this);
Preprocessor::missingIncludeFlag = false;
std::istringstream src("#include \"missing.h\"\n");
std::string processedFile;
std::list<std::string> cfg;
std::list<std::string> paths;
ASSERT_EQUALS(false, Preprocessor::missingIncludeFlag);
preprocessor.preprocess(src, processedFile, cfg, "test.c", paths);
ASSERT_EQUALS(true, Preprocessor::missingIncludeFlag);
}
void inline_suppression_for_missing_include() {
Settings settings;
settings._inlineSuppressions = true;