Fixed #4931 (Wrong calculation of constants (simplifying: +,<<,% operations))

This commit is contained in:
Daniel Marjamäki 2015-11-20 19:43:11 +01:00
parent 094b4c8b6f
commit 8fd62e0cf9
2 changed files with 11 additions and 0 deletions

View File

@ -3734,6 +3734,14 @@ bool Tokenizer::simplifyTokenList2()
simplifyCasts();
for (Token *tok = list.front(); tok; tok = tok->next()) {
if (Token::Match(tok, "%oror%|&& %num% %oror%|&&|,|)") ||
Token::Match(tok, "[(,] %num% %oror%|&&")) {
tok = tok->next();
tok->str(MathLib::isNullValue(tok->str()) ? "0" : "1");
}
}
// Simplify simple calculations before replace constants, this allows the replacement of constants that are calculated
// e.g. const static int value = sizeof(X)/sizeof(Y);
simplifyCalculations();

View File

@ -5660,6 +5660,9 @@ private:
// ticket #3964 - simplify numeric calculations in tokenization
ASSERT_EQUALS("char a [ 10 ] ;", tokenizeAndStringify("char a[9+1];"));
// ticket #4931
ASSERT_EQUALS("dostuff ( 1 ) ;", tokenizeAndStringify("dostuff(9&&8);", true));
}
void simplifyCompoundAssignment() {