From 05699537536358ebcb4873850b7b109d7929228b Mon Sep 17 00:00:00 2001 From: Edoardo Prezioso Date: Tue, 8 Nov 2011 22:48:14 +0100 Subject: [PATCH] Fixed ticket #3309 (false positive: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses) --- lib/tokenize.cpp | 4 ++-- test/testtokenize.cpp | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index a021c0377..fdb244d0f 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -7243,8 +7243,8 @@ bool Tokenizer::simplifyRedundantParenthesis() continue; } - if (Token::Match(tok->previous(), "(|[|,|! ( %var% %op% %var% ) ,|]|)") || - Token::Match(tok->previous(), "(|[|,|! ( %var% %op% %num% ) ,|]|)")) { + if (Token::Match(tok->previous(), "(|[|,| ( %var% %op% %var% ) ,|]|)") || + Token::Match(tok->previous(), "(|[|,| ( %var% %op% %num% ) ,|]|)")) { // We have "( var %op% var )", remove the parenthesis tok->deleteThis(); tok = tok->tokAt(2); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index bd2484e70..e5f5da31e 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -241,6 +241,7 @@ private: TEST_CASE(removeParentheses11); // Ticket #2505 TEST_CASE(removeParentheses12); // Ticket #2760 ',(b)=' TEST_CASE(removeParentheses13); + TEST_CASE(removeParentheses14); // Ticket #3309 TEST_CASE(tokenize_double); TEST_CASE(tokenize_strings); @@ -3969,6 +3970,10 @@ private: ASSERT_EQUALS("; x = y [ a + b ] ;", tokenizeAndStringify(";x=y[(a+b)];", false)); } + void removeParentheses14() { + ASSERT_EQUALS("; if ( ! ( i & 1 ) ) { ; } ;", tokenizeAndStringify("; if ( (a & b) == 0 ); ;", false)); + } + void tokenize_double() { const char code[] = "void f()\n" "{\n"