From 0dfbbd0f80babd08b54cec67475396d4f88ed56c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 11 May 2014 08:22:28 +0200 Subject: [PATCH] Fixed #5479 (Tokenizer: don't remove parentheses in code 'a>(2)') --- lib/tokenize.cpp | 7 +++---- test/testtokenize.cpp | 5 +++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index e36082fe0..c288337f3 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -7107,13 +7107,12 @@ bool Tokenizer::simplifyRedundantParentheses() ret = true; } - // Simplify "!!operator !!(%var%|)) ( %num%|%bool% ) %op%|;|,|)" + // Simplify "!!operator !!%var%|)|>|>> ( %num%|%bool% ) %op%|;|,|)" if (Token::Match(tok, "( %bool%|%num% ) %cop%|;|,|)") && tok->strAt(-2) != "operator" && tok->previous() && - !tok->previous()->isName() && - tok->previous()->str() != ")" && - (!isCPP() || tok->previous()->str() != ">")) { + !Token::Match(tok->previous(), "%var%|)") && + (!(isCPP() && Token::Match(tok->previous(),">|>>")))) { tok->link()->deleteThis(); tok->deleteThis(); ret = true; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 7f2ae29c6..a1acfc6ed 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -369,6 +369,7 @@ private: TEST_CASE(removeParentheses17); // Don't remove parentheses in 'a ? b : (c>0 ? d : e);' TEST_CASE(removeParentheses18); // 'float(*a)[2]' => 'float *a[2]' TEST_CASE(removeParentheses19); // ((typeof(x) *)0) + TEST_CASE(removeParentheses20); // Ticket #5479: a>(2); TEST_CASE(tokenize_double); TEST_CASE(tokenize_strings); @@ -5658,6 +5659,10 @@ private: ASSERT_EQUALS("( ( ( typeof ( X ) ) * ) 0 )", tokenizeAndStringify("(((typeof(X))*)0)", false)); } + void removeParentheses20() { + ASSERT_EQUALS("a < b < int > > ( 2 ) ;", tokenizeAndStringify("a>(2);", false)); + } + void tokenize_double() { const char code[] = "void f()\n" "{\n"