Preprocessor: quick fix for #7939
This commit is contained in:
parent
d6b6f31fbd
commit
865588950a
|
@ -302,6 +302,7 @@ static void getConfigs(const simplecpp::TokenList &tokens, std::set<std::string>
|
|||
{
|
||||
std::vector<std::string> configs_if;
|
||||
std::vector<std::string> configs_ifndef;
|
||||
std::string elseError;
|
||||
|
||||
for (const simplecpp::Token *tok = tokens.cfront(); tok; tok = tok->next) {
|
||||
if (tok->op != '#' || sameline(tok->previous, tok))
|
||||
|
@ -336,6 +337,16 @@ static void getConfigs(const simplecpp::TokenList &tokens, std::set<std::string>
|
|||
tok = tok->previous;
|
||||
continue;
|
||||
}
|
||||
if (cmdtok->str == "else" &&
|
||||
cmdtok->next &&
|
||||
!sameline(cmdtok,cmdtok->next) &&
|
||||
sameline(cmdtok->next, cmdtok->next->next) &&
|
||||
cmdtok->next->op == '#' &&
|
||||
cmdtok->next->next->str == "error") {
|
||||
if (!elseError.empty())
|
||||
elseError += ';';
|
||||
elseError += cfg(configs_if, userDefines);
|
||||
}
|
||||
if (!configs_if.empty())
|
||||
configs_if.pop_back();
|
||||
if (cmdtok->str == "elif") {
|
||||
|
@ -363,6 +374,8 @@ static void getConfigs(const simplecpp::TokenList &tokens, std::set<std::string>
|
|||
defined.insert(cmdtok->next->str);
|
||||
}
|
||||
}
|
||||
if (!elseError.empty())
|
||||
ret.insert(elseError);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -76,6 +76,7 @@ private:
|
|||
TEST_CASE(error3);
|
||||
TEST_CASE(error4); // #2919 - wrong filename is reported
|
||||
TEST_CASE(error5);
|
||||
TEST_CASE(error6);
|
||||
|
||||
TEST_CASE(setPlatformInfo);
|
||||
|
||||
|
@ -364,6 +365,18 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void error6() {
|
||||
const char filedata[] = "#ifdef A\n"
|
||||
"#else\n"
|
||||
"#error 1\n"
|
||||
"#endif\n"
|
||||
"#ifdef B\n"
|
||||
"#else\n"
|
||||
"#error 2\n"
|
||||
"#endif\n";
|
||||
ASSERT_EQUALS("\nA\nA;B\nB\n", getConfigsStr(filedata));
|
||||
}
|
||||
|
||||
void setPlatformInfo() {
|
||||
Settings settings;
|
||||
Preprocessor preprocessor(settings, this);
|
||||
|
|
Loading…
Reference in New Issue