diff --git a/src/tokenize.cpp b/src/tokenize.cpp index 745d41df1..35ab06f94 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -849,8 +849,9 @@ void Tokenizer::simplifyTokenList() // Simple calculations.. - for (bool done = false; !done; done = true) + for (bool done = false; !done; ) { + done = true; for (Token *tok = _tokens; tok; tok = tok->next()) { if (Token::simpleMatch(tok->next(), "* 1") || Token::simpleMatch(tok->next(), "1 *")) @@ -896,6 +897,15 @@ void Tokenizer::simplifyTokenList() done = false; } + + // Remove parantheses around number.. + if (!tok->isName() && Token::Match(tok->next(), "( %num% )")) + { + tok->deleteNext(); + tok = tok->next(); + tok->deleteNext(); + done = false; + } } } diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index f0e206ba0..7f45b90c7 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -42,6 +42,7 @@ private: TEST_CASE(combine_strings); TEST_CASE(double_plus); TEST_CASE(redundant_plus); + TEST_CASE(parantheses1); } std::string tok(const char code[]) @@ -281,6 +282,13 @@ private: ASSERT_EQUALS("void foo ( int a , int b ) { a = a - b ; } ", tok(code1)); } } + + + void parantheses1() + { + const char code1[] = "<= (10+100);"; + ASSERT_EQUALS("<= 110 ; ", tok(code1)); + } }; REGISTER_TEST(TestSimplifyTokens)