Fixed #7604 (simplifyCalculation: expression '0 && x[2]' is not simplified properly)

This commit is contained in:
Daniel Marjamäki 2016-07-17 15:52:53 +02:00
parent 801fd8f96a
commit 45ee29d5dc
2 changed files with 4 additions and 2 deletions

View File

@ -1032,9 +1032,9 @@ bool TemplateSimplifier::simplifyCalculations(Token *_tokens)
const Token *tok2 = tok;
bool andAnd = (tok->next()->str() == "&&");
for (; tok2; tok2 = tok2->next()) {
if (tok2->str() == "(")
if (tok2->str() == "(" || tok2->str() == "[")
++par;
else if (tok2->str() == ")") {
else if (tok2->str() == ")" || tok2->str() == "]") {
if (par == 0)
break;
--par;

View File

@ -5720,6 +5720,8 @@ private:
// ticket #3723 - Simplify condition (0 && a < 123)
ASSERT_EQUALS("( 0 )",
tokenizeAndStringify("( 0 && a < 123 )", true));
ASSERT_EQUALS("( 0 )",
tokenizeAndStringify("( 0 && a[123] )", true));
// ticket #3964 - simplify numeric calculations in tokenization
ASSERT_EQUALS("char a [ 10 ] ;", tokenizeAndStringify("char a[9+1];"));