Fixed #8074 (Preprocessor::getConfigs: wrong configuration extracted 'A;B;;')

This commit is contained in:
Daniel Marjamäki 2017-05-24 11:16:41 +02:00
parent 3930f2d6bc
commit 099b4435c3
2 changed files with 22 additions and 3 deletions

View File

@ -352,9 +352,12 @@ static void getConfigs(const simplecpp::TokenList &tokens, std::set<std::string>
sameline(cmdtok->next, cmdtok->next->next) &&
cmdtok->next->op == '#' &&
cmdtok->next->next->str == "error") {
if (!elseError.empty())
elseError += ';';
elseError += cfg(configs_if, userDefines);
const std::string &ifcfg = cfg(configs_if, userDefines);
if (!ifcfg.empty()) {
if (!elseError.empty())
elseError += ';';
elseError += ifcfg;
}
}
if (!configs_if.empty())
configs_if.pop_back();

View File

@ -79,6 +79,7 @@ private:
TEST_CASE(error4); // #2919 - wrong filename is reported
TEST_CASE(error5);
TEST_CASE(error6);
TEST_CASE(error7);
TEST_CASE(setPlatformInfo);
@ -409,6 +410,21 @@ private:
}
void error7() { // #8074
const char filedata[] = "#define A\n"
"\n"
"#if defined(B)\n"
"#else\n"
"#error \"1\"\n"
"#endif\n"
"\n"
"#if defined(A)\n"
"#else\n"
"#error \"2\"\n"
"#endif\n";
ASSERT_EQUALS("\nB\n", getConfigsStr(filedata));
}
void setPlatformInfo() {
Settings settings;
Preprocessor preprocessor(settings, this);