Skip to content

Commit 58c6d2c

Browse files
authored
refs #1059 - extract configurations for #if x <= y and #if x >= y (#8037)
1 parent ad9563f commit 58c6d2c

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/preprocessor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ static std::string readcondition(const simplecpp::Token *iftok, const std::set<s
410410
return next1->str();
411411
}
412412

413-
if (len == 3 && cond->name && next1->str() == "==" && next2->number) {
413+
if (len == 3 && cond->name && (next1->str() == "==" || next1->str() == "<=" || next1->str() == ">=") && next2->number) {
414414
if (defined.find(cond->str()) == defined.end())
415415
return cond->str() + '=' + cond->next->next->str();
416416
}

test/testpreprocessor.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,8 @@ class TestPreprocessor : public TestFixture {
317317
TEST_CASE(getConfigs11); // #9832 - include guards
318318
TEST_CASE(getConfigs12); // #14222
319319
TEST_CASE(getConfigs13); // #14222
320+
TEST_CASE(getConfigs14); // #1059
321+
TEST_CASE(getConfigs15); // #1059
320322
TEST_CASE(getConfigsError);
321323

322324
TEST_CASE(getConfigsD1);
@@ -2288,6 +2290,20 @@ class TestPreprocessor : public TestFixture {
22882290
ASSERT_EQUALS("\n", getConfigsStr(filedata, nullptr, "gnu.cfg"));
22892291
}
22902292

2293+
void getConfigs14() { // #1059
2294+
const char filedata[] = "#if A >= 1\n"
2295+
"1\n"
2296+
"#endif\n";
2297+
ASSERT_EQUALS("\nA=1\n", getConfigsStr(filedata));
2298+
}
2299+
2300+
void getConfigs15() { // #1059
2301+
const char filedata[] = "#if A <= 1\n"
2302+
"1\n"
2303+
"#endif\n";
2304+
ASSERT_EQUALS("\nA=1\n", getConfigsStr(filedata));
2305+
}
2306+
22912307
void getConfigsError() {
22922308
const char filedata1[] = "#ifndef X\n"
22932309
"#error \"!X\"\n"

0 commit comments

Comments
 (0)