File tree Expand file tree Collapse file tree 3 files changed +11
-6
lines changed Expand file tree Collapse file tree 3 files changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -3665,7 +3665,7 @@ void Tokenizer::simplifyExternC()
36653665 }
36663666}
36673667
3668- void Tokenizer::simplifyRoundCurlyParentheses ()
3668+ void Tokenizer::simplifyCompoundStatements ()
36693669{
36703670 for (Token *tok = list.front (); tok; tok = tok->next ()) {
36713671 while (Token::Match (tok, " [;{}:] ( {" ) &&
@@ -3683,6 +3683,8 @@ void Tokenizer::simplifyRoundCurlyParentheses()
36833683 tok->deleteThis ();
36843684 tok->deleteNext (3 );
36853685 }
3686+ else if (tok->str () == " (" )
3687+ tok = tok->link ();
36863688 }
36873689}
36883690
@@ -5615,8 +5617,8 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
56155617 if (isCPP ())
56165618 simplifyExternC ();
56175619
5618- // simplify weird but legal code : "[;{}] ( { code; } ) ;"->"[;{}] code;"
5619- simplifyRoundCurlyParentheses ();
5620+ // simplify compound statements : "[;{}] ( { code; } ) ;"->"[;{}] code;"
5621+ simplifyCompoundStatements ();
56205622
56215623 // check for simple syntax errors..
56225624 for (const Token *tok = list.front (); tok; tok = tok->next ()) {
Original file line number Diff line number Diff line change @@ -311,7 +311,7 @@ class CPPCHECKLIB Tokenizer {
311311
312312 void simplifyExternC ();
313313
314- void simplifyRoundCurlyParentheses ();
314+ void simplifyCompoundStatements ();
315315
316316 void simplifyTypeIntrinsics ();
317317
Original file line number Diff line number Diff line change @@ -310,7 +310,7 @@ class TestTokenizer : public TestFixture {
310310 TEST_CASE (simplifyCAlternativeTokens);
311311
312312 // x = ({ 123; }); => { x = 123; }
313- TEST_CASE (simplifyRoundCurlyParentheses );
313+ TEST_CASE (simplifyCompoundStatements );
314314
315315 TEST_CASE (simplifyOperatorName1);
316316 TEST_CASE (simplifyOperatorName2);
@@ -5059,9 +5059,12 @@ class TestTokenizer : public TestFixture {
50595059 ignore_errout ();
50605060 }
50615061
5062- void simplifyRoundCurlyParentheses () {
5062+ void simplifyCompoundStatements () {
50635063 ASSERT_EQUALS (" ; x = 123 ;" , tokenizeAndStringify (" ;x=({123;});" ));
50645064 ASSERT_EQUALS (" ; x = y ;" , tokenizeAndStringify (" ;x=({y;});" ));
5065+ // #13419: Do not simplify compound statements in for loop
5066+ ASSERT_EQUALS (" void foo ( int x ) { for ( ; ( { { } ; x < 1 ; } ) ; ) }" ,
5067+ tokenizeAndStringify (" void foo(int x) { for (;({ {}; x<1; });) }" ));
50655068 }
50665069
50675070 void simplifyOperatorName1 () {
You can’t perform that action at this time.
0 commit comments