diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index c75b479b2..31954b142 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -1317,13 +1317,20 @@ std::string Preprocessor::getcode(const std::string &filedata, std::string cfg, if (line.compare(0, 8, "#define ") == 0) { - std::string::size_type pos = line.find_first_of(" (", 8); - if (pos == std::string::npos) - cfgmap[line.substr(8)] = ""; - else if (line[pos] == ' ') - cfgmap[line.substr(8, pos - 8)] = line.substr(pos + 1); - else - cfgmap[line.substr(8, pos - 8)] = ""; + match = true; + for (std::list::const_iterator it = matching_ifdef.begin(); it != matching_ifdef.end(); ++it) + match &= bool(*it); + + if (match) + { + std::string::size_type pos = line.find_first_of(" (", 8); + if (pos == std::string::npos) + cfgmap[line.substr(8)] = ""; + else if (line[pos] == ' ') + cfgmap[line.substr(8, pos - 8)] = line.substr(pos + 1); + else + cfgmap[line.substr(8, pos - 8)] = ""; + } } else if (line.find("#elif ") == 0) diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index ff71cf0f3..1941363d8 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -186,7 +186,8 @@ private: // define and then ifdef TEST_CASE(define_ifdef); - TEST_CASE(define_ifndef); + TEST_CASE(define_ifndef1); + TEST_CASE(define_ifndef2); TEST_CASE(endfile); TEST_CASE(redundant_config); @@ -2217,7 +2218,7 @@ private: } } - void define_ifndef() + void define_ifndef1() { const char filedata[] = "#define A(x) (x)\n" "#ifndef A\n" @@ -2236,6 +2237,21 @@ private: ASSERT_EQUALS(2, actual.size()); } + void define_ifndef2() + { + const char filedata[] = "#ifdef A\n" + "#define B char\n" + "#endif\n" + "#ifndef B\n" + "#define B int\n" + "#endif\n" + "B me;\n"; + + // Preprocess => actual result.. + ASSERT_EQUALS("\n\n\n\n\n\nint me;\n", Preprocessor::getcode(filedata, "", "a.cpp", NULL, NULL)); + ASSERT_EQUALS("\n\n\n\n\n\nchar me;\n", Preprocessor::getcode(filedata, "A", "a.cpp", NULL, NULL)); + } + void redundant_config() { const char filedata[] = "int main() {\n"