Preprocessor: handle '#undef' better. Ticket: #2131

This commit is contained in:
Daniel Marjamaki 2011-10-24 19:51:00 +02:00
parent 08ba378730
commit 0eb4e3032a
2 changed files with 20 additions and 0 deletions

View File

@ -1798,6 +1798,10 @@ std::string Preprocessor::handleIncludes(const std::string &code, const std::str
}
}
else if (line.compare(0,7,"#undef ") == 0) {
defs.erase(line.substr(7));
}
else {
ostr << line;
}

View File

@ -2912,6 +2912,22 @@ private:
ASSERT_EQUALS("\n\n\n\n\n\n\n4\n\n", actual);
}
}
// #undef
{
const std::string code("#ifndef X\n"
"#define X\n"
"123\n"
"#endif\n");
defs.clear();
const std::string actual1(preprocessor.handleIncludes(code,filePath,includePaths,defs));
defs.clear();
const std::string actual(preprocessor.handleIncludes(code + "#undef X\n" + code, filePath, includePaths, defs));
ASSERT_EQUALS(actual1 + "\n" + actual1, actual);
}
}
};