Fixed #3323 (#undef needs different handling)
This commit is contained in:
parent
5953ed7318
commit
8e2c40b4b3
|
@ -1422,7 +1422,7 @@ std::string Preprocessor::getcode(const std::string &filedata, const std::string
|
|||
std::stack<unsigned int> lineNumbers;
|
||||
std::istringstream istr(filedata);
|
||||
std::string line;
|
||||
while (getline(istr, line)) {
|
||||
while (std::getline(istr, line)) {
|
||||
++lineno;
|
||||
|
||||
if (line.compare(0, 11, "#pragma asm") == 0) {
|
||||
|
@ -1496,6 +1496,11 @@ std::string Preprocessor::getcode(const std::string &filedata, const std::string
|
|||
}
|
||||
}
|
||||
|
||||
else if (line.compare(0, 7, "#undef ") == 0) {
|
||||
const std::string name(line.substr(7));
|
||||
cfgmap.erase(name);
|
||||
}
|
||||
|
||||
else if (!emptymatch && line.compare(0, 7, "#elif !") == 0) {
|
||||
if (matched_ifdef.back()) {
|
||||
matching_ifdef.back() = false;
|
||||
|
|
|
@ -205,6 +205,7 @@ private:
|
|||
TEST_CASE(define_ifdef);
|
||||
TEST_CASE(define_ifndef1);
|
||||
TEST_CASE(define_ifndef2);
|
||||
TEST_CASE(undef_ifdef);
|
||||
TEST_CASE(endfile);
|
||||
|
||||
TEST_CASE(redundant_config);
|
||||
|
@ -2634,6 +2635,18 @@ private:
|
|||
ASSERT_EQUALS("\n\n\n\n\n\n$char me;\n", preprocessor.getcode(filedata, "A", "a.cpp"));
|
||||
}
|
||||
|
||||
void undef_ifdef() {
|
||||
const char filedata[] = "#undef A\n"
|
||||
"#ifdef A\n"
|
||||
"123\n"
|
||||
"#endif\n";
|
||||
|
||||
// Preprocess => actual result..
|
||||
Preprocessor preprocessor(NULL, this);
|
||||
ASSERT_EQUALS("\n\n\n\n", preprocessor.getcode(filedata, "", "a.cpp"));
|
||||
ASSERT_EQUALS("\n\n\n\n", preprocessor.getcode(filedata, "A", "a.cpp"));
|
||||
}
|
||||
|
||||
void redundant_config() {
|
||||
const char filedata[] = "int main() {\n"
|
||||
"#ifdef FOO\n"
|
||||
|
|
Loading…
Reference in New Issue