diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index b10ff859ad6..93a7ce62bf1 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -415,6 +415,17 @@ static std::string readcondition(const simplecpp::Token *iftok, const std::setstr() + '=' + 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 781f6b6cf35..2ab97638407 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -319,6 +319,8 @@ class TestPreprocessor : public TestFixture { 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); @@ -653,7 +655,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() { @@ -2304,6 +2306,20 @@ class TestPreprocessor : public TestFixture { 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"