Fixed #4931 (Wrong calculation for '2|0*0&2>>1+0%2*1')

This commit is contained in:
Daniel Marjamäki 2015-11-27 15:02:49 +01:00
parent 1977a18a1e
commit 1bf547c716
2 changed files with 3 additions and 1 deletions

View File

@ -1074,7 +1074,8 @@ bool TemplateSimplifier::simplifyCalculations(Token *_tokens)
} }
if (tok->str() == "0") { if (tok->str() == "0") {
if (Token::Match(tok->previous(), "[+-|] 0")) { if ((Token::Match(tok->previous(), "[+-] 0 %cop%|;") && isLowerThanMulDiv(tok->next())) ||
(Token::Match(tok->previous(), "%or% 0 %cop%|;") && isLowerThanXor(tok->next()))) {
tok = tok->previous(); tok = tok->previous();
if (Token::Match(tok->tokAt(-4), "[;{}] %name% = %name% [+-|] 0 ;") && if (Token::Match(tok->tokAt(-4), "[;{}] %name% = %name% [+-|] 0 ;") &&
tok->strAt(-3) == tok->previous()->str()) { tok->strAt(-3) == tok->previous()->str()) {

View File

@ -2097,6 +2097,7 @@ private:
ASSERT_EQUALS("x ( 1 )", tok("x(9&&8%5%4/3)")); // #4931 ASSERT_EQUALS("x ( 1 )", tok("x(9&&8%5%4/3)")); // #4931
ASSERT_EQUALS("x ( 1 )", tok("x(2 && 2|5<<2%4)")); // #4931 ASSERT_EQUALS("x ( 1 )", tok("x(2 && 2|5<<2%4)")); // #4931
ASSERT_EQUALS("x ( -2 << 6 | 1 )", tok("x(1-3<<6|5/3)")); // #4931 ASSERT_EQUALS("x ( -2 << 6 | 1 )", tok("x(1-3<<6|5/3)")); // #4931
ASSERT_EQUALS("x ( 2 )", tok("x(2|0*0&2>>1+0%2*1)")); // #4931
// don't remove these spaces.. // don't remove these spaces..
ASSERT_EQUALS("new ( auto ) ( 4 ) ;", tok("new (auto)(4);")); ASSERT_EQUALS("new ( auto ) ( 4 ) ;", tok("new (auto)(4);"));