Fixed #3285 (wrong #elif behaviour)
This commit is contained in:
parent
b6b5416b42
commit
73f3b2074b
|
@ -1754,44 +1754,7 @@ std::string Preprocessor::handleIncludes(const std::string &code, const std::str
|
|||
while (std::getline(istr,line)) {
|
||||
++linenr;
|
||||
|
||||
if (line.compare(0,9,"#include ")==0) {
|
||||
std::string filename(line.substr(9));
|
||||
|
||||
const HeaderTypes headerType = getHeaderFileName(filename);
|
||||
if (headerType == NoHeader) {
|
||||
ostr << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
// try to open file
|
||||
std::ifstream fin;
|
||||
if (!openHeader(filename, includePaths, headerType == UserHeader ? path : std::string(""), fin)) {
|
||||
|
||||
if (_settings && (headerType == UserHeader || _settings->debugwarnings)) {
|
||||
if (!_settings->nomsg.isSuppressed("missingInclude", "", 0)) {
|
||||
missingIncludeFlag = true;
|
||||
|
||||
missingInclude(Path::toNativeSeparators(filePath),
|
||||
linenr,
|
||||
filename,
|
||||
headerType == UserHeader);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// Prevent that files are recursively included
|
||||
if (std::find(includes.begin(), includes.end(), filename) != includes.end()) {
|
||||
ostr << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
includes.push_back(filename);
|
||||
|
||||
ostr << "#file \"" << filename << "\"\n"
|
||||
<< handleIncludes(read(fin, filename, NULL), filename, includePaths, defs, includes) << std::endl
|
||||
<< "#endfile";
|
||||
} else if (line.compare(0,7,"#ifdef ") == 0) {
|
||||
if (line.compare(0,7,"#ifdef ") == 0) {
|
||||
if (indent == indentmatch && defs.find(getdef(line,true)) != defs.end()) {
|
||||
elseIsTrue = false;
|
||||
indentmatch++;
|
||||
|
@ -1859,6 +1822,47 @@ std::string Preprocessor::handleIncludes(const std::string &code, const std::str
|
|||
error(filePath, linenr, line.substr(7));
|
||||
}
|
||||
|
||||
else if (line.compare(0,9,"#include ")==0) {
|
||||
std::string filename(line.substr(9));
|
||||
|
||||
const HeaderTypes headerType = getHeaderFileName(filename);
|
||||
if (headerType == NoHeader) {
|
||||
ostr << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
// try to open file
|
||||
std::ifstream fin;
|
||||
if (!openHeader(filename, includePaths, headerType == UserHeader ? path : std::string(""), fin)) {
|
||||
|
||||
if (_settings && (headerType == UserHeader || _settings->debugwarnings)) {
|
||||
if (!_settings->nomsg.isSuppressed("missingInclude", "", 0)) {
|
||||
missingIncludeFlag = true;
|
||||
|
||||
missingInclude(Path::toNativeSeparators(filePath),
|
||||
linenr,
|
||||
filename,
|
||||
headerType == UserHeader);
|
||||
}
|
||||
}
|
||||
ostr << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Prevent that files are recursively included
|
||||
if (std::find(includes.begin(), includes.end(), filename) != includes.end()) {
|
||||
ostr << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
includes.push_back(filename);
|
||||
|
||||
ostr << "#file \"" << filename << "\"\n"
|
||||
<< handleIncludes(read(fin, filename, NULL), filename, includePaths, defs, includes) << std::endl
|
||||
<< "#endfile\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
ostr << line;
|
||||
}
|
||||
|
||||
|
|
|
@ -2981,6 +2981,21 @@ private:
|
|||
preprocessor.handleIncludes(code,"test.c",includePaths,defs);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
// #3285 - #elif
|
||||
{
|
||||
const std::string code("#ifdef GNU\n"
|
||||
"#elif defined(WIN32)\n"
|
||||
"#include \"missing-include!!.h\"\n"
|
||||
"#endif");
|
||||
defs.clear();
|
||||
defs["GNU"] = "";
|
||||
|
||||
errout.str("");
|
||||
settings = Settings();
|
||||
preprocessor.handleIncludes(code,"test.c",includePaths,defs);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue