From 9083c7a728e5ee777a3366b65a82bb2d4985241e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Thu, 9 Jul 2026 12:06:02 +0200 Subject: [PATCH 1/2] add test --- test/testtokenize.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 0617007744a..524d266d93d 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -2273,6 +2273,11 @@ class TestTokenizer : public TestFixture { const char code4[] = "union U { struct { int a; int b; }; int ab[2]; };"; const char expected4[] = "union U { struct { int a ; int b ; } ; int ab [ 2 ] ; } ;"; ASSERT_EQUALS(expected4, tokenizeAndStringify(code4)); + + // #14836: FP syntaxError for anonymous struct in for loop + const char code5[] = "void f(void) { for (struct { int a; } it = {0}; it.a < 10; it.a++) {} }"; + const char expected5[] = "void f ( ) { struct Anonymous0 { int a ; } ; for ( struct Anonymous0 it = { 0 } ; it . a < 10 ; it . a ++ ) { } }"; + ASSERT_EQUALS(expected5, tokenizeAndStringify(code5)); } void vardecl1() { From da1603b2b6b28674c673cb702d905847b86ab82c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Thu, 9 Jul 2026 12:06:11 +0200 Subject: [PATCH 2/2] fix --- lib/tokenize.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index d2ad6f581e7..02d8d0871f9 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -8973,7 +8973,7 @@ void Tokenizer::findGarbageCode() const if (tok->strAt(-1) == ",") syntaxError(tok); colons++; - } else if (tok->str() == "(") { // skip pairs of ( ) + } else if (tok->str() == "(" || tok->str() == "{") { // skip pairs of ( ) tok = tok->link(); } } @@ -9417,6 +9417,7 @@ void Tokenizer::simplifyStructDecl() if (Token::Match(after->next(), "const|static|volatile| *|&| const| (| %type% )| ,|;|[|=|(|{")) { after->insertToken(";"); after = after->next(); + Token *declEnd = after; while (!Token::Match(start, "struct|class|union|enum")) { after->insertToken(start->str()); after = after->next(); @@ -9459,6 +9460,16 @@ void Tokenizer::simplifyStructDecl() } } } + + // pull declaration out of for loop + if (Token::simpleMatch(start->tokAt(-2), "for ( struct")) { + Token *link = start->linkAt(-1); + start->deletePrevious(2); + declEnd->insertToken("("); + declEnd->next()->link(link); + link->link(declEnd->next()); + declEnd->insertToken("for"); + } } }