Skip to content
Open
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 @@ -8830,17 +8830,19 @@ void Tokenizer::findGarbageCode() const
continue;
// count number of semicolons
int semicolons = 0, colons = 0;
const Token* const startTok = tok;
tok = tok->linkAt(1)->previous(); // find ")" of the for-loop
// walk backwards until we find the beginning (startTok) of the for() again
for (; tok != startTok; tok = tok->previous()) {
const Token* const endTok = tok->linkAt(1);
for (tok = tok->tokAt(2); tok != endTok; tok = tok->next()) {
if (const Token* lam = findLambdaEndTokenWithoutAST(tok)) {
tok = lam;
continue;
}
if (tok->str() == ";") { // do the counting
semicolons++;
} else if (tok->str() == ":") {
if (tok->strAt(-1) == ",")
syntaxError(tok);
colons++;
} else if (tok->str() == ")") { // skip pairs of ( )
} else if (tok->str() == "(") { // skip pairs of ( )
tok = tok->link();
}
}
Expand Down
4 changes: 4 additions & 0 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7683,6 +7683,10 @@ class TestTokenizer : public TestFixture {

ASSERT_NO_THROW(tokenizeAndStringify("struct S { unsigned u:2, :30; };")); // #14393

ASSERT_NO_THROW(tokenizeAndStringify("void f() {\n" // #14395
" for (int i : [](int a, int b) { ++a; ++b; return std::vector<int>{a, b}; }(1, 2)) {}\n"
"}\n"));

ignore_errout();
}

Expand Down
Loading