Fixed #5479 (Tokenizer: don't remove parentheses in code 'a<b<c>>(2)')
This commit is contained in:
parent
8e13c74695
commit
0dfbbd0f80
|
@ -7107,13 +7107,12 @@ bool Tokenizer::simplifyRedundantParentheses()
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Simplify "!!operator !!(%var%|)) ( %num%|%bool% ) %op%|;|,|)"
|
// Simplify "!!operator !!%var%|)|>|>> ( %num%|%bool% ) %op%|;|,|)"
|
||||||
if (Token::Match(tok, "( %bool%|%num% ) %cop%|;|,|)") &&
|
if (Token::Match(tok, "( %bool%|%num% ) %cop%|;|,|)") &&
|
||||||
tok->strAt(-2) != "operator" &&
|
tok->strAt(-2) != "operator" &&
|
||||||
tok->previous() &&
|
tok->previous() &&
|
||||||
!tok->previous()->isName() &&
|
!Token::Match(tok->previous(), "%var%|)") &&
|
||||||
tok->previous()->str() != ")" &&
|
(!(isCPP() && Token::Match(tok->previous(),">|>>")))) {
|
||||||
(!isCPP() || tok->previous()->str() != ">")) {
|
|
||||||
tok->link()->deleteThis();
|
tok->link()->deleteThis();
|
||||||
tok->deleteThis();
|
tok->deleteThis();
|
||||||
ret = true;
|
ret = true;
|
||||||
|
|
|
@ -369,6 +369,7 @@ private:
|
||||||
TEST_CASE(removeParentheses17); // Don't remove parentheses in 'a ? b : (c>0 ? d : e);'
|
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(removeParentheses18); // 'float(*a)[2]' => 'float *a[2]'
|
||||||
TEST_CASE(removeParentheses19); // ((typeof(x) *)0)
|
TEST_CASE(removeParentheses19); // ((typeof(x) *)0)
|
||||||
|
TEST_CASE(removeParentheses20); // Ticket #5479: a<b<int>>(2);
|
||||||
|
|
||||||
TEST_CASE(tokenize_double);
|
TEST_CASE(tokenize_double);
|
||||||
TEST_CASE(tokenize_strings);
|
TEST_CASE(tokenize_strings);
|
||||||
|
@ -5658,6 +5659,10 @@ private:
|
||||||
ASSERT_EQUALS("( ( ( typeof ( X ) ) * ) 0 )", tokenizeAndStringify("(((typeof(X))*)0)", false));
|
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() {
|
void tokenize_double() {
|
||||||
const char code[] = "void f()\n"
|
const char code[] = "void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
|
Loading…
Reference in New Issue