diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 3cc639135..0ff3bd059 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -1104,10 +1104,13 @@ void Preprocessor::simplifyCondition(const std::map &v const std::map::const_iterator it = variables.find(tok->str()); if (it != variables.end()) { - if (it->second.empty()) - tok->deleteThis(); - else + if (!it->second.empty()) tok->str(it->second); + else if ((!tok->previous() || tok->strAt(-1) == "||" || tok->strAt(-1) == "&&" || tok->strAt(-1) == "(") && + (!tok->next() || tok->strAt(1) == "||" || tok->strAt(1) == "&&" || tok->strAt(-1) == ")")) + tok->str("1"); + else + tok->deleteThis(); } } diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 2427cd2e9..cf1546369 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -111,7 +111,8 @@ private: TEST_CASE(if_cond9); TEST_CASE(if_cond10); - TEST_CASE(if_or); + TEST_CASE(if_or_1); + TEST_CASE(if_or_2); TEST_CASE(multiline1); TEST_CASE(multiline2); @@ -1068,7 +1069,7 @@ private: - void if_or() + void if_or_1() { const char filedata[] = "#if defined(DEF_10) || defined(DEF_11)\n" "a1;\n" @@ -1097,6 +1098,15 @@ private: } + void if_or_2() + { + const std::string code("#if X || Y\n" + "a1;\n" + "#endif\n"); + const std::string actual = Preprocessor::getcode(code, "X", "test.c", NULL); + ASSERT_EQUALS("\na1;\n\n", actual); + } + void multiline1() {