Skip to content

Commit 771daae

Browse files
committed
fix
1 parent 315ce2e commit 771daae

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

‎lib/tokenize.cpp‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8944,6 +8944,16 @@ void Tokenizer::findGarbageCode() const
89448944
"typedef",
89458945
"while" };
89468946

8947+
const auto hasTopLevelSemicolon = [](const Token *brace) {
8948+
for (const Token *tok = brace->next(); tok && tok != brace->link(); tok = tok->next()) {
8949+
if (Token::Match(tok, "(|[|{") && tok->link())
8950+
tok = tok->link();
8951+
else if (tok->str() == ";")
8952+
return true;
8953+
}
8954+
return false;
8955+
};
8956+
89478957
for (const Token *tok = tokens(); tok; tok = tok->next()) {
89488958
// initialization: = {
89498959
if (Token::simpleMatch(tok, "= {") && Token::simpleMatch(tok->linkAt(1), "} ("))
@@ -8995,6 +9005,17 @@ void Tokenizer::findGarbageCode() const
89959005
syntaxError(tok);
89969006
}
89979007

9008+
if (Token::Match(tok, "(|, {") && !Token::Match(tok->linkAt(1)->previous(), ";|}") && hasTopLevelSemicolon(tok->next())) {
9009+
const Token *par = tok;
9010+
while (par && !Token::Match(par, "(|;|{")) {
9011+
if (Token::Match(par, ")|]|}"))
9012+
par = par->link();
9013+
par = par->previous();
9014+
}
9015+
if (par && par->str() == "(" && Token::Match(par->previous(), "%name% (") && !par->previous()->isKeyword())
9016+
unknownMacroError(par->previous());
9017+
}
9018+
89989019
if (tok->isControlFlowKeyword()) {
89999020
if (Token::Match(tok, "if|while|for|switch")) { // if|while|for|switch (EXPR) { ... }
90009021
if (tok->previous() && !Token::Match(tok->previous(), "%name%|:|;|{|}|)")) {

0 commit comments

Comments
 (0)