File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8537,13 +8537,15 @@ void Tokenizer::findGarbageCode() const
85378537 if (!Token::simpleMatch (tok, " for (" )) // find for loops
85388538 continue ;
85398539 // count number of semicolons
8540- int semicolons = 0 ;
8540+ int semicolons = 0 , colons = 0 ;
85418541 const Token* const startTok = tok;
85428542 tok = tok->next ()->link ()->previous (); // find ")" of the for-loop
85438543 // walk backwards until we find the beginning (startTok) of the for() again
85448544 for (; tok != startTok; tok = tok->previous ()) {
85458545 if (tok->str () == " ;" ) { // do the counting
85468546 semicolons++;
8547+ } else if (tok->str () == " :" ) {
8548+ colons++;
85478549 } else if (tok->str () == " )" ) { // skip pairs of ( )
85488550 tok = tok->link ();
85498551 }
@@ -8553,6 +8555,8 @@ void Tokenizer::findGarbageCode() const
85538555 syntaxError (tok);
85548556 if (semicolons == 1 && !(isCPP () && mSettings .standards .cpp >= Standards::CPP20))
85558557 syntaxError (tok);
8558+ if (semicolons == 0 && colons == 0 )
8559+ syntaxError (tok);
85568560 }
85578561
85588562 // Operators without operands..
Original file line number Diff line number Diff line change @@ -1174,8 +1174,7 @@ class TestGarbage : public TestFixture {
11741174 }
11751175
11761176 void garbageCode142 () { // #7050
1177- checkCode (" { } ( ) { void mapGraphs ( ) { node_t * n ; for (!oid n ) { } } } { }" );
1178- (void )errout_str (); // we are not interested in the output
1177+ ASSERT_THROW (checkCode (" { } ( ) { void mapGraphs ( ) { node_t * n ; for (!oid n ) { } } } { }" ), InternalError);
11791178 }
11801179
11811180 void garbageCode143 () { // #6922
@@ -1312,8 +1311,7 @@ class TestGarbage : public TestFixture {
13121311 ASSERT_THROW (checkCode (code), InternalError);
13131312
13141313 code = " void f1() { for (int n = 0 n < 10 n++); }" ;
1315- checkCode (code);
1316- (void )errout_str (); // we are not interested in the output
1314+ ASSERT_THROW (checkCode (code), InternalError);
13171315 }
13181316
13191317 void garbageSymbolDatabase () {
Original file line number Diff line number Diff line change @@ -7048,6 +7048,8 @@ class TestTokenizer : public TestFixture {
70487048 ASSERT_THROW_EQUALS (tokenizeAndStringify (" int (*f) MACRO((void *));\n " ), // #12010
70497049 InternalError,
70507050 " There is an unknown macro here somewhere. Configuration is required. If MACRO is a macro then please configure it." );
7051+
7052+ ASSERT_THROW (tokenizeAndStringify (" { for (()()) }" ), InternalError); // #11643
70517053 }
70527054
70537055
You can’t perform that action at this time.
0 commit comments