From 8e2c40b4b34fbb795ae72061d28a91cab01dae5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 24 Jan 2012 07:43:26 +0100 Subject: [PATCH] Fixed #3323 (#undef needs different handling) --- lib/preprocessor.cpp | 7 ++++++- test/testpreprocessor.cpp | 13 +++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 2bebef65b..6c37e43a1 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -1422,7 +1422,7 @@ std::string Preprocessor::getcode(const std::string &filedata, const std::string std::stack 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; diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 4aaa837ed..41842c189 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -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"