Fixed #3285 (wrong #elif behaviour)

This commit is contained in:
Daniel Marjamäki 2011-11-03 19:05:48 +01:00
parent b6b5416b42
commit 73f3b2074b
2 changed files with 57 additions and 38 deletions

View File

@ -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;
}

View File

@ -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());
}
}
};