Tokenizer: Fixed simplification of parentheses in expression 'a=(b,c);'

This commit is contained in:
Daniel Marjamäki 2020-09-29 12:06:30 +02:00
parent 31c800e19e
commit f956dee58a
2 changed files with 22 additions and 0 deletions

View File

@ -8098,6 +8098,21 @@ bool Tokenizer::simplifyRedundantParentheses()
continue;
}
// Do not simplify if there is comma inside parantheses..
if (Token::Match(tok->previous(), "%op% (") || Token::Match(tok->link(), ") %op%")) {
bool innerComma = false;
for (const Token *inner = tok->link()->previous(); inner != tok; inner = inner->previous()) {
if (inner->str() == ")")
inner = inner->link();
if (inner->str() == ",") {
innerComma = true;
break;
}
}
if (innerComma)
continue;
}
// !!operator = ( x ) ;
if (tok->strAt(-2) != "operator" &&
tok->previous() && tok->previous()->str() == "=" &&

View File

@ -253,6 +253,7 @@ private:
TEST_CASE(removeParentheses22);
TEST_CASE(removeParentheses23); // Ticket #6103 - Infinite loop upon valid input
TEST_CASE(removeParentheses24); // Ticket #7040
TEST_CASE(removeParentheses25); // daca@home - a=(b,c)
TEST_CASE(tokenize_double);
TEST_CASE(tokenize_strings);
@ -3463,6 +3464,12 @@ private:
ASSERT_EQUALS(exp, tokenizeAndStringify(code));
}
void removeParentheses25() { // daca@home - a=(b,c)
static char code[] = "a=(b,c);";
static char exp[] = "a = ( b , c ) ;";
ASSERT_EQUALS(exp, tokenizeAndStringify(code));
}
void tokenize_double() {
const char code[] = "void f() {\n"
" double a = 4.2;\n"