diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 3cad39045..01a8568a8 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -371,6 +371,8 @@ static void getConfigs(const simplecpp::TokenList &tokens, std::set configs_ifndef.pop_back(); } else if (cmdtok->str == "error") { if (!configs_ifndef.empty() && !configs_ifndef.back().empty()) { + if (configs_ifndef.size() == 1U) + ret.erase(""); std::vector configs(configs_if); configs.push_back(configs_ifndef.back()); ret.insert(cfg(configs, userDefines)); @@ -379,8 +381,11 @@ static void getConfigs(const simplecpp::TokenList &tokens, std::set const std::string &last = configs_if.back(); if (last.size() > 2U && last.compare(last.size()-2U,2,"=0") == 0) { std::vector configs(configs_if); + ret.erase(cfg(configs, userDefines)); configs[configs.size() - 1U] = last.substr(0,last.size()-2U); ret.insert(cfg(configs, userDefines)); + if (configs.size() == 1U) + ret.erase(""); } } } else if (cmdtok->str == "define" && sameline(tok, cmdtok->next) && cmdtok->next->name) { diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 40a541570..8a834e769 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -324,12 +324,12 @@ private: const char filedata1[] = "#ifndef A\n" "#error\n" "#endif\n"; - TODO_ASSERT_EQUALS("A\n", "\nA\n", getConfigsStr(filedata1)); + ASSERT_EQUALS("A\n", getConfigsStr(filedata1)); const char filedata2[] = "#if !A\n" "#error\n" "#endif\n"; - TODO_ASSERT_EQUALS("A\n", "\nA\nA=0\n", getConfigsStr(filedata2)); + ASSERT_EQUALS("A\n", getConfigsStr(filedata2)); } void error3() { @@ -2098,7 +2098,7 @@ private: const char filedata1[] = "#ifndef X\n" "#error \"!X\"\n" "#endif\n"; - ASSERT_EQUALS("\nX\n", getConfigsStr(filedata1)); + ASSERT_EQUALS("X\n", getConfigsStr(filedata1)); const char filedata2[] = "#ifdef X\n" "#ifndef Y\n"