Fixed #6670 (Analysis failed when there are {} in LHS in compound assignment)
This commit is contained in:
parent
35eb1a393d
commit
05a21d45eb
|
@ -4572,7 +4572,8 @@ void Tokenizer::simplifyCompoundAssignment()
|
|||
// Simplify compound assignments:
|
||||
// "a+=b" => "a = a + b"
|
||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||
if (Token::Match(tok, "[;{}] (| *| (| %name%")) {
|
||||
if (!Token::Match(tok, "[;{}] (| *| (| %name%"))
|
||||
continue;
|
||||
// backup current token..
|
||||
Token * const tok1 = tok;
|
||||
|
||||
|
@ -4664,9 +4665,9 @@ void Tokenizer::simplifyCompoundAssignment()
|
|||
// Copy token from lhs to rhs
|
||||
tok->insertToken(tok2->str());
|
||||
tok->next()->varId(tok2->varId());
|
||||
if (Token::Match(tok->next(), "]|)"))
|
||||
if (Token::Match(tok->next(), "]|)|}"))
|
||||
tokend.push(tok->next());
|
||||
else if (Token::Match(tok->next(), "(|[")) {
|
||||
else if (Token::Match(tok->next(), "(|[|{")) {
|
||||
Token::createMutualLinks(tok->next(), tokend.top());
|
||||
tokend.pop();
|
||||
}
|
||||
|
@ -4674,7 +4675,6 @@ void Tokenizer::simplifyCompoundAssignment()
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Tokenizer::simplifyConditions()
|
||||
{
|
||||
|
|
|
@ -582,7 +582,7 @@ private:
|
|||
}
|
||||
|
||||
void garbageCode49() { // #6715
|
||||
ASSERT_THROW(checkCode(" ( ( ) ) { } ( { ( __builtin_va_arg_pack ( ) ) ; } ) { ( int { ( ) ( ( ) ) } ( ) { } ( ) ) += ( ) }"), InternalError);
|
||||
checkCode(" ( ( ) ) { } ( { ( __builtin_va_arg_pack ( ) ) ; } ) { ( int { ( ) ( ( ) ) } ( ) { } ( ) ) += ( ) }");
|
||||
}
|
||||
|
||||
void garbageCode50() { // #6718
|
||||
|
@ -735,7 +735,7 @@ private:
|
|||
}
|
||||
|
||||
void garbageCode87() { // #6788
|
||||
ASSERT_THROW(checkCode("((X (128))) (int a) { v[ = {} (x 42) a] += }"), InternalError); // do not crash
|
||||
checkCode("((X (128))) (int a) { v[ = {} (x 42) a] += }"); // do not crash
|
||||
}
|
||||
|
||||
void garbageCode88() { // #6786
|
||||
|
|
|
@ -6024,6 +6024,7 @@ private:
|
|||
ASSERT_EQUALS("; * p = * p + y ;", tokenizeAndStringify("; *p += y;"));
|
||||
ASSERT_EQUALS("; ( * p ) = ( * p ) + y ;", tokenizeAndStringify("; (*p) += y;"));
|
||||
ASSERT_EQUALS("; * ( p [ 0 ] ) = * ( p [ 0 ] ) + y ;", tokenizeAndStringify("; *(p[0]) += y;"));
|
||||
ASSERT_EQUALS("; p [ { 1 , 2 } ] = p [ { 1 , 2 } ] + y ;", tokenizeAndStringify("; p[{1,2}] += y;"));
|
||||
|
||||
ASSERT_EQUALS("void foo ( ) { switch ( n ) { case 0 : ; x = x + y ; break ; } }", tokenizeAndStringify("void foo() { switch (n) { case 0: x += y; break; } }"));
|
||||
|
||||
|
|
Loading…
Reference in New Issue