Fixed #2871 (Define in source not set when -D is used)

This commit is contained in:
Daniel Marjamäki 2011-07-16 16:59:06 +02:00
parent 74d086d5a0
commit c55b0ff651
2 changed files with 19 additions and 1 deletions

View File

@ -1722,7 +1722,12 @@ std::string Preprocessor::getcode(const std::string &filedata, const std::string
if (pos == std::string::npos) if (pos == std::string::npos)
cfgmap[line.substr(8)] = ""; cfgmap[line.substr(8)] = "";
else if (line[pos] == ' ') else if (line[pos] == ' ')
cfgmap[line.substr(8, pos - 8)] = line.substr(pos + 1); {
std::string value(line.substr(pos + 1));
if (cfgmap.find(value) != cfgmap.end())
value = cfgmap[value];
cfgmap[line.substr(8, pos - 8)] = value;
}
else else
cfgmap[line.substr(8, pos - 8)] = ""; cfgmap[line.substr(8, pos - 8)] = "";
} }

View File

@ -225,6 +225,7 @@ private:
// Using -D to predefine symbols // Using -D to predefine symbols
TEST_CASE(predefine1); TEST_CASE(predefine1);
TEST_CASE(predefine2); TEST_CASE(predefine2);
TEST_CASE(predefine3);
} }
@ -2889,6 +2890,18 @@ private:
} }
} }
void predefine3()
{
// #2871 - define in source is not used if -D is used
const char code[] = "#define X 1\n"
"#define Y X\n"
"#if (X == Y)\n"
"Fred & Wilma\n"
"#endif\n";
const Settings settings;
const std::string actual = Preprocessor::getcode(code, "TEST", "test.c", &settings, this);
ASSERT_EQUALS("\n\n\nFred & Wilma\n\n", actual);
}
}; };
REGISTER_TEST(TestPreprocessor) REGISTER_TEST(TestPreprocessor)