diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index c26475fdb..9abf974b1 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -1176,7 +1176,7 @@ void Preprocessor::simplifyCondition(const std::map &v 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->next() || tok->strAt(1) == "||" || tok->strAt(1) == "&&" || tok->strAt(1) == ")")) tok->str("1"); else tok->deleteThis(); @@ -1200,6 +1200,17 @@ void Preprocessor::simplifyCondition(const std::map &v } } + for (Token *tok = const_cast(tokenizer.tokens()); tok; tok = tok->next()) + { + while ((tok->str() == "(" || tok->str() == "||") && (Token::simpleMatch(tok->tokAt(2), "|| 1"))) + { + tok->deleteNext(); + tok->deleteNext(); + if (tok->tokAt(-3)) + tok = tok->tokAt(-3); + } + } + if (Token::simpleMatch(tokenizer.tokens(), "( 1 )") || Token::simpleMatch(tokenizer.tokens(), "( 1 ||")) condition = "1"; diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 49a54f1db..37ca80744 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -1143,8 +1143,8 @@ private: const std::string code("#if X || Y\n" "a1;\n" "#endif\n"); - const std::string actual = Preprocessor::getcode(code, "X", "test.c", NULL, NULL); - ASSERT_EQUALS("\na1;\n\n", actual); + ASSERT_EQUALS("\na1;\n\n", Preprocessor::getcode(code, "X", "test.c", NULL, NULL)); + ASSERT_EQUALS("\na1;\n\n", Preprocessor::getcode(code, "Y", "test.c", NULL, NULL)); }