diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index f22a82283..44f2af933 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -352,6 +352,12 @@ static void getConfigs(const simplecpp::TokenList &tokens, std::set configs_if.pop_back(); if (!configs_ifndef.empty()) configs_ifndef.pop_back(); + } else if (cmdtok->str == "error") { + if (!configs_ifndef.empty() && !configs_ifndef.back().empty()) { + std::vector configs(configs_if); + configs.push_back(configs_ifndef.back()); + ret.insert(cfg(configs, userDefines)); + } } else if (cmdtok->str == "define" && sameline(tok, cmdtok->next) && cmdtok->next->name) { defined.insert(cmdtok->next->str); } diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 3a022aff2..bb037ddc9 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -215,6 +215,7 @@ private: TEST_CASE(getConfigs7e); TEST_CASE(getConfigs8); // #if A==1 => cfg: A=1 TEST_CASE(getConfigs10); // #5139 + TEST_CASE(getConfigsError); TEST_CASE(getConfigsD1); @@ -2066,6 +2067,20 @@ private: ASSERT_EQUALS("\n", getConfigsStr(filedata)); } + void getConfigsError() { + const char filedata1[] = "#ifndef X\n" + "#error \"!X\"\n" + "#endif\n"; + ASSERT_EQUALS("\nX\n", getConfigsStr(filedata1)); + + const char filedata2[] = "#ifdef X\n" + "#ifndef Y\n" + "#error \"!Y\"\n" + "#endif\n" + "#endif\n"; + ASSERT_EQUALS("\nX\nX;Y\n", getConfigsStr(filedata2)); + } + void getConfigsD1() { const char filedata[] = "#ifdef X\n" "#else\n"