Skip to content

Commit 7ab7065

Browse files
committed
Fixed #10170 (Preprocessor; Fail to extract some configurations)
1 parent b7c4aec commit 7ab7065

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

lib/preprocessor.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,16 @@ static void getConfigs(const simplecpp::TokenList &tokens, std::set<std::string>
459459
std::vector<std::string> configs(configs_if);
460460
configs.push_back(configs_ifndef.back());
461461
ret.erase(cfg(configs, userDefines));
462+
std::set<std::string> temp;
463+
temp.swap(ret);
464+
for (const std::string &c: temp) {
465+
if (c.find(configs_ifndef.back()) != std::string::npos)
466+
ret.insert(c);
467+
else if (c.empty())
468+
ret.insert(configs.empty() ? configs_ifndef.back() : "");
469+
else
470+
ret.insert(c + ";" + configs_ifndef.back());
471+
}
462472
if (!elseError.empty())
463473
elseError += ';';
464474
elseError += cfg(configs_ifndef, userDefines);

test/testpreprocessor.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class TestPreprocessor : public TestFixture {
8181
TEST_CASE(error5);
8282
TEST_CASE(error6);
8383
TEST_CASE(error7);
84+
TEST_CASE(error8); // #10170 -> previous #if configurations
8485

8586
TEST_CASE(setPlatformInfo);
8687

@@ -427,6 +428,19 @@ class TestPreprocessor : public TestFixture {
427428
ASSERT_EQUALS("\nB\n", getConfigsStr(filedata));
428429
}
429430

431+
void error8() {
432+
const char filedata[] = "#ifdef A\n"
433+
"#ifdef B\n"
434+
"#endif\n"
435+
"#else\n"
436+
"#endif\n"
437+
"\n"
438+
"#ifndef C\n"
439+
"#error aa\n"
440+
"#endif";
441+
ASSERT_EQUALS("A;B;C\nA;C\nC\n", getConfigsStr(filedata));
442+
}
443+
430444
void setPlatformInfo() {
431445
Settings settings;
432446
Preprocessor preprocessor(settings, this);
@@ -2134,7 +2148,7 @@ class TestPreprocessor : public TestFixture {
21342148
"#error \"!Y\"\n"
21352149
"#endif\n"
21362150
"#endif\n";
2137-
ASSERT_EQUALS("\nX\nY\n", getConfigsStr(filedata2));
2151+
ASSERT_EQUALS("\nX;Y\nY\n", getConfigsStr(filedata2));
21382152
}
21392153

21402154
void getConfigsD1() {

0 commit comments

Comments
 (0)