Fixed #2571 (Preprocessor: better handling for #undef)

This commit is contained in:
Greg Hewgill 2011-02-11 18:51:22 +01:00 committed by Daniel Marjamäki
parent 751f8d46e5
commit f2f2d1f885
2 changed files with 21 additions and 1 deletions

View File

@ -1544,7 +1544,8 @@ std::string Preprocessor::getcode(const std::string &filedata, std::string cfg,
return "";
}
if (!match && line.compare(0, 8, "#define ") == 0)
if (!match && (line.compare(0, 8, "#define ") == 0 ||
line.compare(0, 6, "#undef") == 0))
{
// Remove define that is not part of this configuration
line = "";

View File

@ -2483,6 +2483,25 @@ private:
ASSERT_EQUALS("\n\n1\n\n", actual[""]);
ASSERT_EQUALS(1, (int)actual.size());
}
{
const char filedata[] = "#define A 1\n"
"#if 0\n"
"#undef A\n"
"#endif\n"
"A\n";
// Preprocess => actual result..
std::istringstream istr(filedata);
std::map<std::string, std::string> actual;
Settings settings;
Preprocessor preprocessor(&settings, this);
preprocessor.preprocess(istr, actual, "file.c");
// Compare results..
ASSERT_EQUALS("\n\n\n\n1\n", actual[""]);
ASSERT_EQUALS(1, (int)actual.size());
}
}
void define_ifndef1()