diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index e2257db4b..a8bc0719c 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -459,6 +459,16 @@ static void getConfigs(const simplecpp::TokenList &tokens, std::set std::vector configs(configs_if); configs.push_back(configs_ifndef.back()); ret.erase(cfg(configs, userDefines)); + std::set temp; + temp.swap(ret); + for (const std::string &c: temp) { + if (c.find(configs_ifndef.back()) != std::string::npos) + ret.insert(c); + else if (c.empty()) + ret.insert(configs.empty() ? configs_ifndef.back() : ""); + else + ret.insert(c + ";" + configs_ifndef.back()); + } if (!elseError.empty()) elseError += ';'; elseError += cfg(configs_ifndef, userDefines); diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 25ca848e5..961415ec7 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -81,6 +81,7 @@ private: TEST_CASE(error5); TEST_CASE(error6); TEST_CASE(error7); + TEST_CASE(error8); // #10170 -> previous #if configurations TEST_CASE(setPlatformInfo); @@ -427,6 +428,19 @@ private: ASSERT_EQUALS("\nB\n", getConfigsStr(filedata)); } + void error8() { + const char filedata[] = "#ifdef A\n" + "#ifdef B\n" + "#endif\n" + "#else\n" + "#endif\n" + "\n" + "#ifndef C\n" + "#error aa\n" + "#endif"; + ASSERT_EQUALS("A;B;C\nA;C\nC\n", getConfigsStr(filedata)); + } + void setPlatformInfo() { Settings settings; Preprocessor preprocessor(settings, this); @@ -2134,7 +2148,7 @@ private: "#error \"!Y\"\n" "#endif\n" "#endif\n"; - ASSERT_EQUALS("\nX\nY\n", getConfigsStr(filedata2)); + ASSERT_EQUALS("\nX;Y\nY\n", getConfigsStr(filedata2)); } void getConfigsD1() {