Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() != ";") {
Expand Down Expand Up @@ -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() == ",") {
Expand Down
6 changes: 6 additions & 0 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down