Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7835,18 +7835,6 @@ bool Tokenizer::simplifyRedundantParentheses()
ret = true;
}

if (Token::simpleMatch(tok->previous(), "? (") && Token::simpleMatch(tok->link(), ") :")) {
const Token *tok2 = tok->next();
while (tok2 && (Token::Match(tok2,"%bool%|%num%|%name%") || tok2->isArithmeticalOp()))
tok2 = tok2->next();
if (tok2 && tok2->str() == ")") {
tok->link()->deleteThis();
tok->deleteThis();
ret = true;
continue;
}
}

while (Token::Match(tok->previous(), "[{([,] ( !!{") &&
Token::Match(tok->link(), ") [;,])]") &&
!Token::simpleMatch(tok->tokAt(-2), "operator ,") && // Ticket #5709
Expand Down
9 changes: 8 additions & 1 deletion test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ class TestTokenizer : public TestFixture {
TEST_CASE(removeParentheses25); // daca@home - a=(b,c)
TEST_CASE(removeParentheses26); // Ticket #8875 a[0](0)
TEST_CASE(removeParentheses27);
TEST_CASE(removeParentheses28); // #12164 - don't remove parentheses in '(expr1) ? (expr2) : (expr3);'

TEST_CASE(tokenize_double);
TEST_CASE(tokenize_strings);
Expand Down Expand Up @@ -1809,7 +1810,7 @@ class TestTokenizer : public TestFixture {
void removeParentheses15() {
ASSERT_EQUALS("a = b ? c : 123 ;", tokenizeAndStringify("a = b ? c : (123);"));
ASSERT_EQUALS("a = b ? c : ( 123 + 456 ) ;", tokenizeAndStringify("a = b ? c : ((123)+(456));"));
ASSERT_EQUALS("a = b ? 123 : c ;", tokenizeAndStringify("a = b ? (123) : c;"));
ASSERT_EQUALS("a = b ? ( 123 ) : c ;", tokenizeAndStringify("a = b ? (123) : c;"));

// #4316
ASSERT_EQUALS("a = b ? c : ( d = 1 , 0 ) ;", tokenizeAndStringify("a = b ? c : (d=1,0);"));
Expand Down Expand Up @@ -1918,6 +1919,12 @@ class TestTokenizer : public TestFixture {
ASSERT_EQUALS(exp, tokenizeAndStringify(code));
}

void removeParentheses28() { // Ticket #12164
static char code[] = "temp1 = (value > 100U) ? (value+100U) : (value-50U);";
static const char exp[] = "temp1 = ( value > 100U ) ? ( value + 100U ) : ( value - 50U ) ;";
ASSERT_EQUALS(exp, tokenizeAndStringify(code));
}

void tokenize_double() {
const char code[] = "void f() {\n"
" double a = 4.2;\n"
Expand Down