From d09e1df0d76b24ccd0344140b87ba65c9fb6e42f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 29 May 2010 20:27:08 +0200 Subject: [PATCH] Fixed #1714 (Wrong precedence for shift operators when simplifying calculations?) --- lib/tokenize.cpp | 4 ++-- test/testsimplifytokens.cpp | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 7659d7fde..cde582719 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -5783,7 +5783,7 @@ bool Tokenizer::simplifyCalculations() // (1-2) while (Token::Match(tok, "[[,(=<>+-*] %num% [+-*/] %num% [],);=<>+-*/]") || Token::Match(tok, "<< %num% [+-*/] %num% [],);=<>+-*/]") || - Token::Match(tok, "[[,(=<>+-*] %num% [+-*/] %num% <<") || + Token::Match(tok, "[[,(=<>+-*] %num% [+-*/] %num% <<|>>") || Token::Match(tok, "<< %num% [+-*/] %num% <<")) { tok = tok->next(); @@ -5884,7 +5884,7 @@ bool Tokenizer::simplifyCalculations() } } - if (Token::Match(tok, "%num% <<|>> %num%")) + if (Token::Match(tok->previous(), "[([,=] %num% <<|>> %num%")) { const int op1(MathLib::toLongNumber(tok->str())); const int op2(MathLib::toLongNumber(tok->tokAt(2)->str())); diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 1914b8140..8a943222f 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -2294,6 +2294,9 @@ private: ASSERT_EQUALS("int a [ 8 ] ;", tok("int a[5+6/2];")); ASSERT_EQUALS("int a [ 4 ] ;", tok("int a[(10)-1-5];")); ASSERT_EQUALS("int a [ i - 9 ] ;", tok("int a[i - 10 + 1];")); + + ASSERT_EQUALS("x = 501 ;", tok("x = 1000 + 2 >> 1;")); + ASSERT_EQUALS("x = 125 ;", tok("x = 1000 / 2 >> 2;")); }