From 1bf547c71679f81de8e39dcbbd02eba208cb9d2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 27 Nov 2015 15:02:49 +0100 Subject: [PATCH] Fixed #4931 (Wrong calculation for '2|0*0&2>>1+0%2*1') --- lib/templatesimplifier.cpp | 3 ++- test/testsimplifytokens.cpp | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 8e2018d4b..eccb6b80e 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -1074,7 +1074,8 @@ bool TemplateSimplifier::simplifyCalculations(Token *_tokens) } 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(); if (Token::Match(tok->tokAt(-4), "[;{}] %name% = %name% [+-|] 0 ;") && tok->strAt(-3) == tok->previous()->str()) { diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 549a17938..754475bea 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -2097,6 +2097,7 @@ private: 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 ( -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.. ASSERT_EQUALS("new ( auto ) ( 4 ) ;", tok("new (auto)(4);"));