Fixed #7842 (Preprocessor::getConfigs: #error in #ifndef not handled well)

This commit is contained in:
Daniel Marjamäki 2016-12-03 11:59:48 +01:00
parent afb962575b
commit 9c69546d72
2 changed files with 21 additions and 0 deletions

View File

@ -352,6 +352,12 @@ static void getConfigs(const simplecpp::TokenList &tokens, std::set<std::string>
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<std::string> 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);
}

View File

@ -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"