From 4bfbb5a9a4a150aa89b9e101c8d3768d1bffc554 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 22 Oct 2025 10:34:30 +0200 Subject: [PATCH 1/2] Update tokenize.cpp --- lib/tokenize.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index fd253a2f1ad..506568d1a3b 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -7450,9 +7450,9 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, const Token * const tokEnd, co else if (Token::Match(varName, "%name% [")) { tok2 = varName->next(); - while (Token::Match(tok2->link(), "] ,|=|[")) + while (Token::Match(tok2->link(), "] [,=[{]")) tok2 = tok2->link()->next(); - if (!Token::Match(tok2, "=|,")) + if (!Token::Match(tok2, "[=,{]")) tok2 = nullptr; if (tok2 && tok2->str() == "=") { while (tok2 && tok2->str() != "," && tok2->str() != ";") { @@ -7522,9 +7522,11 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, const Token * const tokEnd, co varTok = varTok->next(); if (!varTok) syntaxError(tok2); // invalid code - TokenList::insertTokens(eq, varTok, 2); - eq->str(";"); - eq->isSplittedVarDeclEq(true); + if (eq->str() == "=") { + TokenList::insertTokens(eq, varTok, 2); + eq->str(";"); + eq->isSplittedVarDeclEq(true); + } // "= x, " => "= x; type " if (tok2->str() == ",") { From 3e0e2b34dc9dcb8cf7abcbdf0e9ed0a9b89acf3f Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 22 Oct 2025 10:37:03 +0200 Subject: [PATCH 2/2] Update testtokenize.cpp --- test/testtokenize.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index d698ca5ce1a..b872a152fa0 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -295,6 +295,7 @@ class TestTokenizer : public TestFixture { TEST_CASE(simplifyInitVar2); TEST_CASE(simplifyInitVar3); TEST_CASE(simplifyInitVar4); + TEST_CASE(simplifyInitVar5); TEST_CASE(bitfields1); TEST_CASE(bitfields2); @@ -4678,6 +4679,11 @@ class TestTokenizer : public TestFixture { "}", tokenizeAndStringify(code)); } + void simplifyInitVar5() { // #14218 + const char code[] = "int c[1]{}, b;"; + ASSERT_EQUALS("int c [ 1 ] { } ; int b ;", tokenizeAndStringify(code)); + } + void bitfields1() { const char code1[] = "struct A { bool x : 1; };"; ASSERT_EQUALS("struct A { bool x ; } ;", tokenizeAndStringify(code1));