diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index c17e21298..4e19737d9 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -1722,7 +1722,12 @@ std::string Preprocessor::getcode(const std::string &filedata, const std::string if (pos == std::string::npos) cfgmap[line.substr(8)] = ""; else if (line[pos] == ' ') - cfgmap[line.substr(8, pos - 8)] = line.substr(pos + 1); + { + std::string value(line.substr(pos + 1)); + if (cfgmap.find(value) != cfgmap.end()) + value = cfgmap[value]; + cfgmap[line.substr(8, pos - 8)] = value; + } else cfgmap[line.substr(8, pos - 8)] = ""; } diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 4e19324ef..948f3ee7b 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -225,6 +225,7 @@ private: // Using -D to predefine symbols TEST_CASE(predefine1); TEST_CASE(predefine2); + TEST_CASE(predefine3); } @@ -2889,6 +2890,18 @@ private: } } + void predefine3() + { + // #2871 - define in source is not used if -D is used + const char code[] = "#define X 1\n" + "#define Y X\n" + "#if (X == Y)\n" + "Fred & Wilma\n" + "#endif\n"; + const Settings settings; + const std::string actual = Preprocessor::getcode(code, "TEST", "test.c", &settings, this); + ASSERT_EQUALS("\n\n\nFred & Wilma\n\n", actual); + } }; REGISTER_TEST(TestPreprocessor)