diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index fe1326852..f8d36d5a7 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3617,9 +3617,6 @@ bool Tokenizer::simplifyTokenList1(const char FileName[]) if (_settings->terminated()) return false; - // f(x=g()) => x=g(); f(x) - simplifyAssignmentInFunctionCall(); - // x = ({ 123; }); => { x = 123; } simplifyAssignmentBlock(); @@ -3730,6 +3727,9 @@ bool Tokenizer::simplifyTokenList2() for (Token *tok = list.front(); tok; tok = tok->next()) tok->clearAst(); + // f(x=g()) => x=g(); f(x) + simplifyAssignmentInFunctionCall(); + simplifyCharAt(); // simplify references diff --git a/test/testother.cpp b/test/testother.cpp index 660791776..5e7ab6387 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -6155,7 +6155,7 @@ private: " int t;\n" " dostuff(t=1,t^c);\n" "}", "test.c"); - TODO_ASSERT_EQUALS("error", "", errout.str()); + ASSERT_EQUALS("[test.c:3]: (error) Expression 't=1,t^c' depends on order of evaluation of side effects\n", errout.str()); // sizeof check("void f(char *buf) {\n" diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 78769c637..440e1a6f1 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -47,6 +47,9 @@ private: // correct order TEST_CASE(simplifyTokenList1); + // foo(p = new char[10]); => p = new char[10]; foo(p); + TEST_CASE(simplifyAssignmentInFunctionCall); + TEST_CASE(cast); TEST_CASE(iftruefalse); TEST_CASE(combine_strings); @@ -341,6 +344,12 @@ private: } + void simplifyAssignmentInFunctionCall() { + ASSERT_EQUALS("; x = g ( ) ; f ( x ) ;", tok(";f(x=g());")); + 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);")); + } + + void cast() { ASSERT_EQUALS("if ( p == 0 ) { ; }", tok("if (p == (char *)0);")); ASSERT_EQUALS("return str ;", tok("return (char *)str;")); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 968b9a2f2..355a5e6eb 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -363,9 +363,6 @@ private: TEST_CASE(simplifyCalculations); - // foo(p = new char[10]); => p = new char[10]; foo(p); - TEST_CASE(simplifyAssignmentInFunctionCall); - // "x += .." => "x = x + .." TEST_CASE(simplifyCompoundAssignment); @@ -5727,11 +5724,6 @@ private: ASSERT_EQUALS("; a = a + ( b = 1 ) ;", tokenizeAndStringify("; a += b = 1;")); } - void simplifyAssignmentInFunctionCall() { - ASSERT_EQUALS("; x = g ( ) ; f ( x ) ;", tokenizeAndStringify(";f(x=g());")); - ASSERT_EQUALS("; hs = ( xyz_t ) { h . centerX , h . centerY , 1 + index } ; putInput ( hs , 1 ) ;", tokenizeAndStringify(";putInput(hs = (xyz_t) { h->centerX, h->centerY, 1 + index }, 1);")); - } - void simplifyRoundCurlyParentheses() { ASSERT_EQUALS("; x = 123 ;", tokenizeAndStringify(";x=({123;});")); ASSERT_EQUALS("; x = y ;", tokenizeAndStringify(";x=({y;});"));