Fixed #5479 (Tokenizer: don't remove parentheses in code 'a<b<c>>(2)')

This commit is contained in:
Daniel Marjamäki 2014-05-11 08:22:28 +02:00
parent 8e13c74695
commit 0dfbbd0f80
2 changed files with 8 additions and 4 deletions

View File

@ -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;

View File

@ -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<b<int>>(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<b<int>>(2);", false));
}
void tokenize_double() {
const char code[] = "void f()\n"
"{\n"