Fixed #4502 (Preprocessor: Treat SystemInclude and UserInclude the same)
This commit is contained in:
parent
e63f2c3b5b
commit
d33341a21a
|
@ -816,10 +816,11 @@ void Preprocessor::preprocess(std::istream &srcCodeStream, std::string &processe
|
||||||
if (!fin.is_open()) {
|
if (!fin.is_open()) {
|
||||||
if (_settings && !_settings->nomsg.isSuppressed("missingInclude", cur, 1)) {
|
if (_settings && !_settings->nomsg.isSuppressed("missingInclude", cur, 1)) {
|
||||||
missingIncludeFlag = true;
|
missingIncludeFlag = true;
|
||||||
|
if (_settings->checkConfiguration) {
|
||||||
missingInclude(Path::toNativeSeparators(Path::getPathFromFilename(cur)),
|
missingInclude(Path::toNativeSeparators(Path::getPathFromFilename(cur)),
|
||||||
1,
|
1,
|
||||||
cur,
|
cur);
|
||||||
true);
|
}
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -2044,16 +2045,13 @@ std::string Preprocessor::handleIncludes(const std::string &code, const std::str
|
||||||
filepath = path;
|
filepath = path;
|
||||||
std::ifstream fin;
|
std::ifstream fin;
|
||||||
if (!openHeader(filename, includePaths, filepath, fin)) {
|
if (!openHeader(filename, includePaths, filepath, fin)) {
|
||||||
|
if (_settings && !_settings->nomsg.isSuppressed("missingInclude", filename, linenr)) {
|
||||||
if (_settings && (headerType == UserHeader || _settings->debugwarnings)) {
|
|
||||||
if (!_settings->nomsg.isSuppressed("missingInclude", filename, linenr)) {
|
|
||||||
missingIncludeFlag = true;
|
missingIncludeFlag = true;
|
||||||
|
|
||||||
|
if (_settings->checkConfiguration)
|
||||||
missingInclude(Path::toNativeSeparators(filePath),
|
missingInclude(Path::toNativeSeparators(filePath),
|
||||||
linenr,
|
linenr,
|
||||||
filename,
|
filename);
|
||||||
headerType == UserHeader);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ostr << std::endl;
|
ostr << std::endl;
|
||||||
continue;
|
continue;
|
||||||
|
@ -2152,7 +2150,7 @@ void Preprocessor::handleIncludes(std::string &code, const std::string &filePath
|
||||||
path = filename;
|
path = filename;
|
||||||
path.erase(1 + path.find_last_of("\\/"));
|
path.erase(1 + path.find_last_of("\\/"));
|
||||||
paths.push_back(path);
|
paths.push_back(path);
|
||||||
} else if (!fileOpened && _settings && (headerType == UserHeader || _settings->debugwarnings)) {
|
} else if (!fileOpened && _settings) {
|
||||||
std::string f = filePath;
|
std::string f = filePath;
|
||||||
|
|
||||||
// Determine line number of include
|
// Determine line number of include
|
||||||
|
@ -2180,8 +2178,7 @@ void Preprocessor::handleIncludes(std::string &code, const std::string &filePath
|
||||||
if (_errorLogger && _settings->checkConfiguration) {
|
if (_errorLogger && _settings->checkConfiguration) {
|
||||||
missingInclude(Path::toNativeSeparators(f),
|
missingInclude(Path::toNativeSeparators(f),
|
||||||
linenr,
|
linenr,
|
||||||
filename,
|
filename);
|
||||||
headerType == UserHeader);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2189,7 +2186,7 @@ void Preprocessor::handleIncludes(std::string &code, const std::string &filePath
|
||||||
}
|
}
|
||||||
|
|
||||||
// Report that include is missing
|
// Report that include is missing
|
||||||
void Preprocessor::missingInclude(const std::string &filename, unsigned int linenr, const std::string &header, bool userheader)
|
void Preprocessor::missingInclude(const std::string &filename, unsigned int linenr, const std::string &header)
|
||||||
{
|
{
|
||||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
|
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
|
||||||
if (!filename.empty()) {
|
if (!filename.empty()) {
|
||||||
|
@ -2198,12 +2195,7 @@ void Preprocessor::missingInclude(const std::string &filename, unsigned int line
|
||||||
loc.setfile(filename);
|
loc.setfile(filename);
|
||||||
locationList.push_back(loc);
|
locationList.push_back(loc);
|
||||||
}
|
}
|
||||||
|
ErrorLogger::ErrorMessage errmsg(locationList, Severity::information, "Include file: \"" + header + "\" not found.", "missingInclude", false);
|
||||||
// If the missing include is a system header then this is
|
|
||||||
// currently a debug-message.
|
|
||||||
const Severity::SeverityType severity = userheader ? Severity::information : Severity::debug;
|
|
||||||
const std::string id = userheader ? "missingInclude" : "debug";
|
|
||||||
ErrorLogger::ErrorMessage errmsg(locationList, severity, "Include file: \"" + header + "\" not found.", id, false);
|
|
||||||
errmsg.file0 = file0;
|
errmsg.file0 = file0;
|
||||||
_errorLogger->reportInfo(errmsg);
|
_errorLogger->reportInfo(errmsg);
|
||||||
}
|
}
|
||||||
|
@ -3004,7 +2996,7 @@ void Preprocessor::getErrorMessages(ErrorLogger *errorLogger, const Settings *se
|
||||||
{
|
{
|
||||||
Settings settings2(*settings);
|
Settings settings2(*settings);
|
||||||
Preprocessor preprocessor(&settings2, errorLogger);
|
Preprocessor preprocessor(&settings2, errorLogger);
|
||||||
preprocessor.missingInclude("", 1, "", true);
|
preprocessor.missingInclude("", 1, "");
|
||||||
preprocessor.validateCfgError("X");
|
preprocessor.validateCfgError("X");
|
||||||
preprocessor.error("", 1, "#error message"); // #error ..
|
preprocessor.error("", 1, "#error message"); // #error ..
|
||||||
}
|
}
|
||||||
|
|
|
@ -244,7 +244,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void missingInclude(const std::string &filename, unsigned int linenr, const std::string &header, bool userheader);
|
void missingInclude(const std::string &filename, unsigned int linenr, const std::string &header);
|
||||||
|
|
||||||
void error(const std::string &filename, unsigned int linenr, const std::string &msg);
|
void error(const std::string &filename, unsigned int linenr, const std::string &msg);
|
||||||
|
|
||||||
|
|
|
@ -3301,6 +3301,12 @@ private:
|
||||||
const std::string code("#include \"missing-include!!.h\"\n");
|
const std::string code("#include \"missing-include!!.h\"\n");
|
||||||
|
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
settings = Settings();
|
||||||
|
preprocessor.handleIncludes(code,"test.c",includePaths,defs);
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
errout.str("");
|
||||||
|
settings.checkConfiguration = true;
|
||||||
preprocessor.handleIncludes(code,"test.c",includePaths,defs);
|
preprocessor.handleIncludes(code,"test.c",includePaths,defs);
|
||||||
ASSERT_EQUALS("[test.c:1]: (information) Include file: \"missing-include!!.h\" not found.\n", errout.str());
|
ASSERT_EQUALS("[test.c:1]: (information) Include file: \"missing-include!!.h\" not found.\n", errout.str());
|
||||||
|
|
||||||
|
@ -3320,9 +3326,9 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
errout.str("");
|
errout.str("");
|
||||||
settings.debugwarnings = true;
|
settings.checkConfiguration = true;
|
||||||
preprocessor.handleIncludes(code,"test.c",includePaths,defs);
|
preprocessor.handleIncludes(code,"test.c",includePaths,defs);
|
||||||
ASSERT_EQUALS("[test.c:1]: (debug) Include file: \"missing-include!!.h\" not found.\n", errout.str());
|
ASSERT_EQUALS("[test.c:1]: (information) Include file: \"missing-include!!.h\" not found.\n", errout.str());
|
||||||
|
|
||||||
errout.str("");
|
errout.str("");
|
||||||
settings.nomsg.addSuppression("missingInclude");
|
settings.nomsg.addSuppression("missingInclude");
|
||||||
|
|
Loading…
Reference in New Issue