From f2f2d1f885d034b26e98fe0d6a9e5a0d97c86bb3 Mon Sep 17 00:00:00 2001 From: Greg Hewgill Date: Fri, 11 Feb 2011 18:51:22 +0100 Subject: [PATCH] Fixed #2571 (Preprocessor: better handling for #undef) --- lib/preprocessor.cpp | 3 ++- test/testpreprocessor.cpp | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 557fea4fa..638e07b29 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -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 = ""; diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index fdeb61d22..09795e370 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -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 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()