Fixed #3405 ((error) Invalid number of character ({) when these macros are def ined: 'WIN32'.)
This commit is contained in:
parent
4cad5d4df4
commit
34fba9e1ea
|
@ -1779,7 +1779,7 @@ std::string Preprocessor::handleIncludes(const std::string &code, const std::str
|
|||
|
||||
if (line.compare(0,7,"#ifdef ") == 0) {
|
||||
if (indent == indentmatch) {
|
||||
std::string tag = getdef(line,true);
|
||||
const std::string tag = getdef(line,true);
|
||||
if (defs.find(tag) != defs.end()) {
|
||||
elseIsTrue = false;
|
||||
indentmatch++;
|
||||
|
@ -1795,7 +1795,7 @@ std::string Preprocessor::handleIncludes(const std::string &code, const std::str
|
|||
elseIsTrue = true;
|
||||
} else if (line.compare(0,8,"#ifndef ") == 0) {
|
||||
if (indent == indentmatch) {
|
||||
std::string tag = getdef(line,false);
|
||||
const std::string tag = getdef(line,false);
|
||||
if (defs.find(tag) == defs.end()) {
|
||||
elseIsTrue = false;
|
||||
indentmatch++;
|
||||
|
@ -1804,11 +1804,12 @@ std::string Preprocessor::handleIncludes(const std::string &code, const std::str
|
|||
indentmatch++;
|
||||
suppressCurrentCodePath = false;
|
||||
}
|
||||
}
|
||||
++indent;
|
||||
|
||||
if (indent == indentmatch + 1)
|
||||
elseIsTrue = true;
|
||||
}
|
||||
|
||||
} else if (!suppressCurrentCodePath && line.compare(0,4,"#if ") == 0) {
|
||||
if (indent == indentmatch && match_cfg_def(defs, line.substr(4))) {
|
||||
elseIsTrue = false;
|
||||
|
|
|
@ -234,6 +234,7 @@ private:
|
|||
// Defines are given: test Preprocessor::handleIncludes
|
||||
TEST_CASE(def_handleIncludes);
|
||||
TEST_CASE(def_missingInclude);
|
||||
TEST_CASE(def_handleIncludes_ifelse); // problems in handleIncludes for #else
|
||||
|
||||
// Using -U to undefine symbols
|
||||
TEST_CASE(undef1);
|
||||
|
@ -3043,6 +3044,48 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
void def_handleIncludes_ifelse() {
|
||||
const std::string filePath("test.c");
|
||||
const std::list<std::string> includePaths;
|
||||
std::map<std::string,std::string> defs;
|
||||
Preprocessor preprocessor(NULL, this);
|
||||
|
||||
// #3405
|
||||
{
|
||||
defs.clear();
|
||||
defs["A"] = "";
|
||||
const std::string code("\n#ifndef PAL_UTIL_UTILS_H_\n"
|
||||
"#define PAL_UTIL_UTILS_H_\n"
|
||||
"1\n"
|
||||
"#ifndef USE_BOOST\n"
|
||||
"2\n"
|
||||
"#else\n"
|
||||
"3\n"
|
||||
"#endif\n"
|
||||
"4\n"
|
||||
"#endif\n"
|
||||
"\n"
|
||||
"#ifndef PAL_UTIL_UTILS_H_\n"
|
||||
"#define PAL_UTIL_UTILS_H_\n"
|
||||
"5\n"
|
||||
"#ifndef USE_BOOST\n"
|
||||
"6\n"
|
||||
"#else\n"
|
||||
"7\n"
|
||||
"#endif\n"
|
||||
"8\n"
|
||||
"#endif\n"
|
||||
"\n");
|
||||
std::string actual(preprocessor.handleIncludes(code,filePath,includePaths,defs));
|
||||
|
||||
// the 1,2,4 should be in the result
|
||||
actual.erase(0, actual.find("1"));
|
||||
while (actual.find("\n") != std::string::npos)
|
||||
actual.erase(actual.find("\n"),1);
|
||||
ASSERT_EQUALS("124", actual);
|
||||
}
|
||||
}
|
||||
|
||||
void undef1() {
|
||||
Settings settings;
|
||||
|
||||
|
|
Loading…
Reference in New Issue