Skip to content

Commit 8171154

Browse files
committed
Fixed cppcheck-opensource#7230 (Confusing code snippet in error message)
1 parent fae9c21 commit 8171154

11 files changed

Lines changed: 173 additions & 100 deletions

lib/astutils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ bool isVariableChanged(const Token *start, const Token *end, const unsigned int
275275
{
276276
for (const Token *tok = start; tok != end; tok = tok->next()) {
277277
if (tok->varId() == varid) {
278-
if (Token::Match(tok, "%name% =|++|--"))
278+
if (Token::Match(tok, "%name% %assign%|++|--"))
279279
return true;
280280

281281
if (Token::Match(tok->previous(), "++|-- %name%"))

lib/checkcondition.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,13 +442,13 @@ void CheckCondition::oppositeInnerCondition()
442442
break;
443443
else if ((tok->varId() && vars.find(tok->varId()) != vars.end()) ||
444444
(!tok->varId() && nonlocal)) {
445-
if (Token::Match(tok, "%name% ++|--|="))
445+
if (Token::Match(tok, "%name% %assign%|++|--"))
446446
break;
447447
if (Token::Match(tok, "%name% [")) {
448448
const Token *tok2 = tok->linkAt(1);
449449
while (Token::simpleMatch(tok2, "] ["))
450450
tok2 = tok2->linkAt(1);
451-
if (Token::simpleMatch(tok2, "] ="))
451+
if (Token::Match(tok2, "] %assign%|++|--"))
452452
break;
453453
}
454454
if (Token::Match(tok->previous(), "++|--|& %name%"))

lib/checkother.cpp

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ void CheckOther::checkRedundantAssignment()
540540
}
541541

542542
std::map<unsigned int, const Token*>::iterator it = varAssignments.find(tok->varId());
543-
if (tok->next() && tok->next()->isAssignmentOp() && Token::Match(startToken, "[;{}]")) { // Assignment
543+
if (Token::simpleMatch(tok->next(), "=") && Token::Match(startToken, "[;{}]")) { // Assignment
544544
if (it != varAssignments.end()) {
545545
bool error = true; // Ensure that variable is not used on right side
546546
for (const Token* tok2 = tok->tokAt(2); tok2; tok2 = tok2->next()) {
@@ -733,6 +733,32 @@ void CheckOther::checkRedundantAssignmentInSwitch()
733733
// Bitwise operation. Report an error if it's performed twice before a break. E.g.:
734734
// case 3: b |= 1; // <== redundant
735735
// case 4: b |= 1;
736+
else if (Token::Match(tok2->previous(), ";|{|}|: %var% %assign% %num% ;") &&
737+
(tok2->strAt(1) == "|=" || tok2->strAt(1) == "&=") &&
738+
Token::Match(tok2->next()->astOperand2(), "%num%")) {
739+
std::string bitOp = tok2->strAt(1)[0] + tok2->strAt(2);
740+
std::map<unsigned int, const Token*>::const_iterator i2 = varsWithBitsSet.find(tok2->varId());
741+
742+
// This variable has not had a bit operation performed on it yet, so just make a note of it
743+
if (i2 == varsWithBitsSet.end()) {
744+
varsWithBitsSet[tok2->varId()] = tok2;
745+
bitOperations[tok2->varId()] = bitOp;
746+
}
747+
748+
// The same bit operation has been performed on the same variable twice, so report an error
749+
else if (bitOperations[tok2->varId()] == bitOp)
750+
redundantBitwiseOperationInSwitchError(i2->second, i2->second->str());
751+
752+
// A different bit operation was performed on the variable, so clear it
753+
else {
754+
varsWithBitsSet.erase(tok2->varId());
755+
bitOperations.erase(tok2->varId());
756+
}
757+
}
758+
759+
// Bitwise operation. Report an error if it's performed twice before a break. E.g.:
760+
// case 3: b = b | 1; // <== redundant
761+
// case 4: b = b | 1;
736762
else if (Token::Match(tok2->previous(), ";|{|}|: %var% = %name% %or%|& %num% ;") &&
737763
tok2->varId() == tok2->tokAt(2)->varId()) {
738764
std::string bitOp = tok2->strAt(3) + tok2->strAt(4);
@@ -2186,7 +2212,7 @@ static bool isNegative(const Token *tok, const Settings *settings)
21862212
void CheckOther::checkNegativeBitwiseShift()
21872213
{
21882214
for (const Token* tok = _tokenizer->tokens(); tok; tok = tok->next()) {
2189-
if (tok->str() != "<<" && tok->str() != ">>")
2215+
if (!Token::Match(tok, "<<|>>|<<=|>>="))
21902216
continue;
21912217

21922218
if (!tok->astOperand1() || !tok->astOperand2())

lib/checkunusedvar.cpp

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,9 @@ static const Token* doAssignment(Variables &variables, const Token *tok, bool de
417417
return tok->tokAt(2);
418418
}
419419

420+
if (Token::Match(tok, "%var% %assign%") && tok->strAt(1) != "=")
421+
return tok->next();
422+
420423
const Token* const tokOld = tok;
421424

422425
// check for aliased variable
@@ -426,7 +429,7 @@ static const Token* doAssignment(Variables &variables, const Token *tok, bool de
426429
if (var1) {
427430
// jump behind '='
428431
tok = tok->next();
429-
while (tok->str() != "=") {
432+
while (!tok->isAssignmentOp()) {
430433
if (tok->varId())
431434
variables.read(tok->varId(), tok);
432435
tok = tok->next();
@@ -862,8 +865,8 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
862865
variables.use(tok->tokAt(2)->varId(), tok);
863866
}
864867
// assignment
865-
else if (Token::Match(tok, "*| ++|--| %name% ++|--| =") ||
866-
Token::Match(tok, "*| ( const| %type% *| ) %name% =")) {
868+
else if (Token::Match(tok, "*| ++|--| %name% ++|--| %assign%") ||
869+
Token::Match(tok, "*| ( const| %type% *| ) %name% %assign%")) {
867870
bool dereference = false;
868871
bool pre = false;
869872
bool post = false;
@@ -873,7 +876,7 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
873876
tok = tok->next();
874877
}
875878

876-
if (Token::Match(tok, "( const| %type% *| ) %name% ="))
879+
if (Token::Match(tok, "( const| %type% *| ) %name% %assign%"))
877880
tok = tok->link()->next();
878881

879882
else if (tok->str() == "(")
@@ -892,6 +895,12 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
892895

893896
tok = doAssignment(variables, tok, dereference, scope);
894897

898+
if (tok && tok->isAssignmentOp() && tok->str() != "=") {
899+
variables.use(varid1, tok);
900+
if (Token::Match(tok, "%assign% %name%"))
901+
tok = tok->next();
902+
}
903+
895904
if (pre || post)
896905
variables.use(varid1, tok);
897906

@@ -939,19 +948,19 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
939948
} else {
940949
variables.write(varid1, tok);
941950
}
951+
}
942952

943-
Variables::VariableUsage *var2 = variables.find(tok->varId());
944-
if (var2) {
945-
if (var2->_type == Variables::reference) {
946-
variables.writeAliases(tok->varId(), tok);
947-
variables.read(tok->varId(), tok);
948-
} else if (tok->varId() != varid1 && Token::Match(tok, "%name% ."))
949-
variables.read(tok->varId(), tok);
950-
else if (tok->varId() != varid1 &&
951-
var2->_type == Variables::standard &&
952-
tok->strAt(-1) != "&")
953-
variables.use(tok->varId(), tok);
954-
}
953+
Variables::VariableUsage *var2 = variables.find(tok->varId());
954+
if (var2) {
955+
if (var2->_type == Variables::reference) {
956+
variables.writeAliases(tok->varId(), tok);
957+
variables.read(tok->varId(), tok);
958+
} else if (tok->varId() != varid1 && Token::Match(tok, "%name% .|["))
959+
variables.read(tok->varId(), tok);
960+
else if (tok->varId() != varid1 &&
961+
var2->_type == Variables::standard &&
962+
tok->strAt(-1) != "&")
963+
variables.use(tok->varId(), tok);
955964
}
956965

957966
const Token * const equal = skipBracketsAndMembers(tok->next());

lib/token.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,11 +362,18 @@ static int multiComparePercent(const Token *tok, const char*& haystack, bool emp
362362
}
363363
break;
364364
case 'a':
365-
// Accept any token (%any%)
365+
// Accept any token (%any%) or assign (%assign%)
366366
{
367-
haystack += 4;
368-
return 1;
367+
if (haystack[3] == '%') { // %any%
368+
haystack += 4;
369+
return 1;
370+
} else { // %assign%
371+
haystack += 7;
372+
if (tok->isAssignmentOp())
373+
return 1;
374+
}
369375
}
376+
break;
370377
case 'n':
371378
// Number (%num%) or name (%name%)
372379
{

lib/tokenize.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3480,9 +3480,6 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
34803480
// simplify '[;{}] * & ( %any% ) =' to '%any% ='
34813481
simplifyMulAndParens();
34823482

3483-
// ";a+=b;" => ";a=a+b;"
3484-
simplifyCompoundAssignment();
3485-
34863483
if (!isC() && !_settings->library.markupFile(FileName)) {
34873484
findComplicatedSyntaxErrorsInTemplates();
34883485
}
@@ -3720,6 +3717,9 @@ bool Tokenizer::simplifyTokenList2()
37203717
// f(x=g()) => x=g(); f(x)
37213718
simplifyAssignmentInFunctionCall();
37223719

3720+
// ";a+=b;" => ";a=a+b;"
3721+
simplifyCompoundAssignment();
3722+
37233723
simplifyCharAt();
37243724

37253725
// simplify references

test/testsimplifytokens.cpp

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ class TestSimplifyTokens : public TestFixture {
5050
// foo(p = new char[10]); => p = new char[10]; foo(p);
5151
TEST_CASE(simplifyAssignmentInFunctionCall);
5252

53+
// ";a+=b;" => ";a=a+b;"
54+
TEST_CASE(simplifyCompoundAssignment);
55+
5356
TEST_CASE(cast);
5457
TEST_CASE(iftruefalse);
5558
TEST_CASE(combine_strings);
@@ -343,12 +346,73 @@ class TestSimplifyTokens : public TestFixture {
343346
tok(";while((x=f())==-1 && errno==EINTR){}",true));
344347
}
345348

346-
347349
void simplifyAssignmentInFunctionCall() {
348350
ASSERT_EQUALS("; x = g ( ) ; f ( x ) ;", tok(";f(x=g());"));
349351
ASSERT_EQUALS("; hs = ( xyz_t ) { h . centerX , h . centerY , 1 + index } ; putInput ( hs , 1 ) ;", tok(";putInput(hs = (xyz_t) { h->centerX, h->centerY, 1 + index }, 1);"));
350352
}
351353

354+
void simplifyCompoundAssignment() {
355+
ASSERT_EQUALS("; x = x + y ;", tok("; x += y;"));
356+
ASSERT_EQUALS("; x = x - y ;", tok("; x -= y;"));
357+
ASSERT_EQUALS("; x = x * y ;", tok("; x *= y;"));
358+
ASSERT_EQUALS("; x = x / y ;", tok("; x /= y;"));
359+
ASSERT_EQUALS("; x = x % y ;", tok("; x %= y;"));
360+
ASSERT_EQUALS("; x = x & y ;", tok("; x &= y;"));
361+
ASSERT_EQUALS("; x = x | y ;", tok("; x |= y;"));
362+
ASSERT_EQUALS("; x = x ^ y ;", tok("; x ^= y;"));
363+
ASSERT_EQUALS("; x = x << y ;", tok("; x <<= y;"));
364+
ASSERT_EQUALS("; x = x >> y ;", tok("; x >>= y;"));
365+
366+
ASSERT_EQUALS("{ x = x + y ; }", tok("{ x += y;}"));
367+
ASSERT_EQUALS("{ x = x - y ; }", tok("{ x -= y;}"));
368+
ASSERT_EQUALS("{ x = x * y ; }", tok("{ x *= y;}"));
369+
ASSERT_EQUALS("{ x = x / y ; }", tok("{ x /= y;}"));
370+
ASSERT_EQUALS("{ x = x % y ; }", tok("{ x %= y;}"));
371+
ASSERT_EQUALS("{ x = x & y ; }", tok("{ x &= y;}"));
372+
ASSERT_EQUALS("{ x = x | y ; }", tok("{ x |= y;}"));
373+
ASSERT_EQUALS("{ x = x ^ y ; }", tok("{ x ^= y;}"));
374+
ASSERT_EQUALS("{ x = x << y ; }", tok("{ x <<= y;}"));
375+
ASSERT_EQUALS("{ x = x >> y ; }", tok("{ x >>= y;}"));
376+
377+
ASSERT_EQUALS("; * p = * p + y ;", tok("; *p += y;"));
378+
ASSERT_EQUALS("; ( * p ) = ( * p ) + y ;", tok("; (*p) += y;"));
379+
ASSERT_EQUALS("; * ( p [ 0 ] ) = * ( p [ 0 ] ) + y ;", tok("; *(p[0]) += y;"));
380+
ASSERT_EQUALS("; p [ { 1 , 2 } ] = p [ { 1 , 2 } ] + y ;", tok("; p[{1,2}] += y;"));
381+
382+
ASSERT_EQUALS("void foo ( ) { switch ( n ) { case 0 : ; x = x + y ; break ; } }", tok("void foo() { switch (n) { case 0: x += y; break; } }"));
383+
384+
ASSERT_EQUALS("; x . y = x . y + 1 ;", tok("; x.y += 1;"));
385+
386+
ASSERT_EQUALS("; x [ 0 ] = x [ 0 ] + 1 ;", tok("; x[0] += 1;"));
387+
ASSERT_EQUALS("; x [ y - 1 ] = x [ y - 1 ] + 1 ;", tok("; x[y-1] += 1;"));
388+
ASSERT_EQUALS("; x [ y ] = x [ y ++ ] + 1 ;", tok("; x[y++] += 1;"));
389+
ASSERT_EQUALS("; x [ ++ y ] = x [ y ] + 1 ;", tok("; x[++y] += 1;"));
390+
391+
ASSERT_EQUALS(";", tok(";x += 0;"));
392+
ASSERT_EQUALS(";", tok(";x += '\\0';"));
393+
ASSERT_EQUALS(";", tok(";x -= 0;"));
394+
ASSERT_EQUALS(";", tok(";x |= 0;"));
395+
ASSERT_EQUALS(";", tok(";x *= 1;"));
396+
ASSERT_EQUALS(";", tok(";x /= 1;"));
397+
398+
ASSERT_EQUALS("; a . x ( ) = a . x ( ) + 1 ;", tok("; a.x() += 1;"));
399+
ASSERT_EQUALS("; x ( 1 ) = x ( 1 ) + 1 ;", tok("; x(1) += 1;"));
400+
401+
// #2368
402+
ASSERT_EQUALS("{ j = j - i ; }", tok("if (false) {} else { j -= i; }"));
403+
404+
// #2714 - wrong simplification of "a += b?c:d;"
405+
ASSERT_EQUALS("; a = a + ( b ? c : d ) ;", tok("; a+=b?c:d;"));
406+
ASSERT_EQUALS("; a = a * ( b + 1 ) ;", tok("; a*=b+1;"));
407+
408+
ASSERT_EQUALS("; a = a + ( b && c ) ;", tok("; a+=b&&c;"));
409+
ASSERT_EQUALS("; a = a * ( b || c ) ;", tok("; a*=b||c;"));
410+
ASSERT_EQUALS("; a = a | ( b == c ) ;", tok("; a|=b==c;"));
411+
412+
// #3469
413+
ASSERT_EQUALS("; a = a + ( b = 1 ) ;", tok("; a += b = 1;"));
414+
}
415+
352416

353417
void cast() {
354418
ASSERT_EQUALS("if ( p == 0 ) { ; }", tok("if (p == (char *)0);"));
@@ -1715,7 +1779,7 @@ class TestSimplifyTokens : public TestFixture {
17151779
}
17161780

17171781
void cAlternativeTokens() {
1718-
ASSERT_EQUALS("void f ( ) { err = err | ( ( r & s ) && ! t ) ; }",
1782+
ASSERT_EQUALS("void f ( ) { err |= ( ( r & s ) && ! t ) ; }",
17191783
tok("void f() { err or_eq ((r bitand s) and not t); }", "test.c", false));
17201784
ASSERT_EQUALS("void f ( ) const { r = f ( a [ 4 ] | 15 , ~ c , ! d ) ; }",
17211785
tok("void f() const { r = f(a[4] bitor 0x0F, compl c, not d) ; }", "test.c", false));

test/testsizeof.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,15 @@ class TestSizeof : public TestFixture {
609609
ASSERT_EQUALS("[test.cpp:4]: (portability) 'p1' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.\n"
610610
"[test.cpp:5]: (portability) 'p2' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.\n", errout.str());
611611

612+
check("void f() {\n"
613+
" void* p1 = malloc(10);\n"
614+
" void* p2 = malloc(5);\n"
615+
" p1-=4;\n"
616+
" p2+=4;\n"
617+
"}");
618+
ASSERT_EQUALS("[test.cpp:4]: (portability) 'p1' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.\n"
619+
"[test.cpp:5]: (portability) 'p2' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.\n", errout.str());
620+
612621
check("void f() {\n"
613622
" void* p = malloc(10);\n"
614623
" int* p2 = &p + 4;\n"

test/testtokenize.cpp

Lines changed: 1 addition & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,6 @@ class TestTokenizer : public TestFixture {
363363

364364
TEST_CASE(simplifyCalculations);
365365

366-
// "x += .." => "x = x + .."
367-
TEST_CASE(simplifyCompoundAssignment);
368-
369366
// x = ({ 123; }); => { x = 123; }
370367
TEST_CASE(simplifyRoundCurlyParentheses);
371368

@@ -3490,7 +3487,7 @@ class TestTokenizer : public TestFixture {
34903487
" n12 = open ( ) ;"
34913488
" n13 = open ( ) ;"
34923489
" n14 = open ( ) ;"
3493-
" n15 = n15 + 10 ; "
3490+
" n15 += 10 ; "
34943491
"}";
34953492
ASSERT_EQUALS(expected, tokenizeAndStringify(code));
34963493
}
@@ -5662,68 +5659,6 @@ class TestTokenizer : public TestFixture {
56625659
ASSERT_EQUALS("dostuff ( 1 ) ;", tokenizeAndStringify("dostuff(9&&8);", true));
56635660
}
56645661

5665-
void simplifyCompoundAssignment() {
5666-
ASSERT_EQUALS("; x = x + y ;", tokenizeAndStringify("; x += y;"));
5667-
ASSERT_EQUALS("; x = x - y ;", tokenizeAndStringify("; x -= y;"));
5668-
ASSERT_EQUALS("; x = x * y ;", tokenizeAndStringify("; x *= y;"));
5669-
ASSERT_EQUALS("; x = x / y ;", tokenizeAndStringify("; x /= y;"));
5670-
ASSERT_EQUALS("; x = x % y ;", tokenizeAndStringify("; x %= y;"));
5671-
ASSERT_EQUALS("; x = x & y ;", tokenizeAndStringify("; x &= y;"));
5672-
ASSERT_EQUALS("; x = x | y ;", tokenizeAndStringify("; x |= y;"));
5673-
ASSERT_EQUALS("; x = x ^ y ;", tokenizeAndStringify("; x ^= y;"));
5674-
ASSERT_EQUALS("; x = x << y ;", tokenizeAndStringify("; x <<= y;"));
5675-
ASSERT_EQUALS("; x = x >> y ;", tokenizeAndStringify("; x >>= y;"));
5676-
5677-
ASSERT_EQUALS("{ x = x + y ; }", tokenizeAndStringify("{ x += y;}"));
5678-
ASSERT_EQUALS("{ x = x - y ; }", tokenizeAndStringify("{ x -= y;}"));
5679-
ASSERT_EQUALS("{ x = x * y ; }", tokenizeAndStringify("{ x *= y;}"));
5680-
ASSERT_EQUALS("{ x = x / y ; }", tokenizeAndStringify("{ x /= y;}"));
5681-
ASSERT_EQUALS("{ x = x % y ; }", tokenizeAndStringify("{ x %= y;}"));
5682-
ASSERT_EQUALS("{ x = x & y ; }", tokenizeAndStringify("{ x &= y;}"));
5683-
ASSERT_EQUALS("{ x = x | y ; }", tokenizeAndStringify("{ x |= y;}"));
5684-
ASSERT_EQUALS("{ x = x ^ y ; }", tokenizeAndStringify("{ x ^= y;}"));
5685-
ASSERT_EQUALS("{ x = x << y ; }", tokenizeAndStringify("{ x <<= y;}"));
5686-
ASSERT_EQUALS("{ x = x >> y ; }", tokenizeAndStringify("{ x >>= y;}"));
5687-
5688-
ASSERT_EQUALS("; * p = * p + y ;", tokenizeAndStringify("; *p += y;"));
5689-
ASSERT_EQUALS("; ( * p ) = ( * p ) + y ;", tokenizeAndStringify("; (*p) += y;"));
5690-
ASSERT_EQUALS("; * ( p [ 0 ] ) = * ( p [ 0 ] ) + y ;", tokenizeAndStringify("; *(p[0]) += y;"));
5691-
ASSERT_EQUALS("; p [ { 1 , 2 } ] = p [ { 1 , 2 } ] + y ;", tokenizeAndStringify("; p[{1,2}] += y;"));
5692-
5693-
ASSERT_EQUALS("void foo ( ) { switch ( n ) { case 0 : ; x = x + y ; break ; } }", tokenizeAndStringify("void foo() { switch (n) { case 0: x += y; break; } }"));
5694-
5695-
ASSERT_EQUALS("; x . y = x . y + 1 ;", tokenizeAndStringify("; x.y += 1;"));
5696-
5697-
ASSERT_EQUALS("; x [ 0 ] = x [ 0 ] + 1 ;", tokenizeAndStringify("; x[0] += 1;"));
5698-
ASSERT_EQUALS("; x [ y - 1 ] = x [ y - 1 ] + 1 ;", tokenizeAndStringify("; x[y-1] += 1;"));
5699-
ASSERT_EQUALS("; x [ y ] = x [ y ++ ] + 1 ;", tokenizeAndStringify("; x[y++] += 1;"));
5700-
ASSERT_EQUALS("; x [ ++ y ] = x [ y ] + 1 ;", tokenizeAndStringify("; x[++y] += 1;"));
5701-
5702-
ASSERT_EQUALS(";", tokenizeAndStringify(";x += 0;"));
5703-
ASSERT_EQUALS(";", tokenizeAndStringify(";x += '\\0';"));
5704-
ASSERT_EQUALS(";", tokenizeAndStringify(";x -= 0;"));
5705-
ASSERT_EQUALS(";", tokenizeAndStringify(";x |= 0;"));
5706-
ASSERT_EQUALS(";", tokenizeAndStringify(";x *= 1;"));
5707-
ASSERT_EQUALS(";", tokenizeAndStringify(";x /= 1;"));
5708-
5709-
ASSERT_EQUALS("; a . x ( ) = a . x ( ) + 1 ;", tokenizeAndStringify("; a.x() += 1;"));
5710-
ASSERT_EQUALS("; x ( 1 ) = x ( 1 ) + 1 ;", tokenizeAndStringify("; x(1) += 1;"));
5711-
5712-
// #2368
5713-
ASSERT_EQUALS("if ( false ) { } else { j = j - i ; }", tokenizeAndStringify("if (false) {} else { j -= i; }"));
5714-
5715-
// #2714 - wrong simplification of "a += b?c:d;"
5716-
ASSERT_EQUALS("; a = a + ( b ? c : d ) ;", tokenizeAndStringify("; a+=b?c:d;"));
5717-
ASSERT_EQUALS("; a = a * ( b + 1 ) ;", tokenizeAndStringify("; a*=b+1;"));
5718-
5719-
ASSERT_EQUALS("; a = a + ( b && c ) ;", tokenizeAndStringify("; a+=b&&c;"));
5720-
ASSERT_EQUALS("; a = a * ( b || c ) ;", tokenizeAndStringify("; a*=b||c;"));
5721-
ASSERT_EQUALS("; a = a | ( b == c ) ;", tokenizeAndStringify("; a|=b==c;"));
5722-
5723-
// #3469
5724-
ASSERT_EQUALS("; a = a + ( b = 1 ) ;", tokenizeAndStringify("; a += b = 1;"));
5725-
}
5726-
57275662
void simplifyRoundCurlyParentheses() {
57285663
ASSERT_EQUALS("; x = 123 ;", tokenizeAndStringify(";x=({123;});"));
57295664
ASSERT_EQUALS("; x = y ;", tokenizeAndStringify(";x=({y;});"));

0 commit comments

Comments
 (0)