diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 636e5a848a1..6101c7b5ce1 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -410,11 +410,22 @@ static std::string readcondition(const simplecpp::Token *iftok, const std::setstr(); } - if (len == 3 && cond->name && next1->str() == "==" && next2->number) { + if (len == 3 && cond->name && (next1->str() == "==" || next1->str() == "<=" || next1->str() == ">=") && next2->number) { if (defined.find(cond->str()) == defined.end()) return cond->str() + '=' + cond->next->next->str(); } + if (len == 3 && cond->name && (next1->op == '<' || next1->op == '>') && next2->number) { + if (defined.find(cond->str()) == defined.end()) { + int v = strToInt(cond->next->next->str()); + if (next1->op == '<') + v -= 1; + else + v += 1; + return cond->str() + '=' + std::to_string(v); + } + } + std::set configset; for (; sameline(iftok,cond); cond = cond->next) { if (cond->op == '!') { diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 369de0d2640..b38c71823f4 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -316,6 +316,10 @@ class TestPreprocessor : public TestFixture { TEST_CASE(getConfigs11); // #9832 - include guards TEST_CASE(getConfigs12); // #14222 TEST_CASE(getConfigs13); // #14222 + TEST_CASE(getConfigs14); // #1059 + TEST_CASE(getConfigs15); // #1059 + TEST_CASE(getConfigs16); // #1059 + TEST_CASE(getConfigs17); // #1059 TEST_CASE(getConfigsError); TEST_CASE(getConfigsD1); @@ -652,7 +656,7 @@ class TestPreprocessor : public TestFixture { "#else\n" " B\n" "#endif\n"; - TODO_ASSERT_EQUALS("\nLIBVER=101\n", "\n", getConfigsStr(filedata)); + ASSERT_EQUALS("\nLIBVER=101\n", getConfigsStr(filedata)); } void if_cond2() { @@ -2289,6 +2293,34 @@ class TestPreprocessor : public TestFixture { ASSERT_EQUALS("\n", getConfigsStr(filedata, nullptr, "gnu.cfg")); } + void getConfigs14() { // #1059 + const char filedata[] = "#if A >= 1\n" + "1\n" + "#endif\n"; + ASSERT_EQUALS("\nA=1\n", getConfigsStr(filedata)); + } + + void getConfigs15() { // #1059 + const char filedata[] = "#if A <= 1\n" + "1\n" + "#endif\n"; + ASSERT_EQUALS("\nA=1\n", getConfigsStr(filedata)); + } + + void getConfigs16() { // #1059 + const char filedata[] = "#if A > 1\n" + "1\n" + "#endif\n"; + ASSERT_EQUALS("\nA=2\n", getConfigsStr(filedata)); + } + + void getConfigs17() { // #1059 + const char filedata[] = "#if A < 1\n" + "1\n" + "#endif\n"; + ASSERT_EQUALS("\nA=0\n", getConfigsStr(filedata)); + } + void getConfigsError() { const char filedata1[] = "#ifndef X\n" "#error \"!X\"\n"