Tokenizer: Fixed simplification of parentheses in expression 'a=(b,c);'
This commit is contained in:
parent
31c800e19e
commit
f956dee58a
|
@ -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() == "=" &&
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue