Fixed #3275 (Missing includes always reported)
This commit is contained in:
parent
e11c1f7975
commit
ed97b62610
|
@ -205,7 +205,7 @@ int CppCheckExecutor::check(int argc, const char* const argv[])
|
||||||
if (!_settings._errorsOnly)
|
if (!_settings._errorsOnly)
|
||||||
reportUnmatchedSuppressions(cppCheck.settings().nomsg.getUnmatchedGlobalSuppressions());
|
reportUnmatchedSuppressions(cppCheck.settings().nomsg.getUnmatchedGlobalSuppressions());
|
||||||
|
|
||||||
if (Preprocessor::missingIncludeFlag) {
|
if (_settings.isEnabled("missingInclude") && Preprocessor::missingIncludeFlag) {
|
||||||
const std::list<ErrorLogger::ErrorMessage::FileLocation> callStack;
|
const std::list<ErrorLogger::ErrorMessage::FileLocation> callStack;
|
||||||
ErrorLogger::ErrorMessage msg(callStack,
|
ErrorLogger::ErrorMessage msg(callStack,
|
||||||
Severity::information,
|
Severity::information,
|
||||||
|
|
|
@ -99,6 +99,9 @@ std::string Settings::addEnabled(const std::string &str)
|
||||||
}
|
}
|
||||||
} else if (id.find(str) != id.end()) {
|
} else if (id.find(str) != id.end()) {
|
||||||
_enabled.insert(str);
|
_enabled.insert(str);
|
||||||
|
if (str == "information") {
|
||||||
|
_enabled.insert("missingInclude");
|
||||||
|
}
|
||||||
} else if (!handled) {
|
} else if (!handled) {
|
||||||
if (str.empty())
|
if (str.empty())
|
||||||
return std::string("cppcheck: --enable parameter is empty");
|
return std::string("cppcheck: --enable parameter is empty");
|
||||||
|
|
|
@ -216,6 +216,9 @@ private:
|
||||||
|
|
||||||
TEST_CASE(invalid_define); // #2605 - hang for: '#define ='
|
TEST_CASE(invalid_define); // #2605 - hang for: '#define ='
|
||||||
|
|
||||||
|
// Show 'missing include' warnings
|
||||||
|
TEST_CASE(missingInclude);
|
||||||
|
|
||||||
// inline suppression, missingInclude
|
// inline suppression, missingInclude
|
||||||
TEST_CASE(inline_suppression_for_missing_include);
|
TEST_CASE(inline_suppression_for_missing_include);
|
||||||
|
|
||||||
|
@ -2756,6 +2759,20 @@ private:
|
||||||
preprocessor.preprocess(src, processedFile, cfg, "", paths); // don't hang
|
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() {
|
void inline_suppression_for_missing_include() {
|
||||||
Settings settings;
|
Settings settings;
|
||||||
settings._inlineSuppressions = true;
|
settings._inlineSuppressions = true;
|
||||||
|
|
Loading…
Reference in New Issue