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: 11 additions & 1 deletion lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ static bool isClassStructUnionEnumStart(const Token * tok)
if (!Token::Match(tok->previous(), "class|struct|union|enum|%name%|>|>> {"))
return false;
const Token * tok2 = tok->previous();
while (tok2 && !Token::Match(tok2, "class|struct|union|enum|{|}|;"))
while (tok2 && !Token::Match(tok2, "class|struct|union|enum|{|}|)|;|>|>>"))
tok2 = tok2->previous();
return Token::Match(tok2, "class|struct|union|enum");
}
Expand Down Expand Up @@ -8776,6 +8776,16 @@ void Tokenizer::findGarbageCode() const
else if (tok->isKeyword() && nonGlobalKeywords.count(tok->str()) && !Token::Match(tok->tokAt(-2), "operator %str%"))
syntaxError(tok, "keyword '" + tok->str() + "' is not allowed in global scope");
}
for (const Token *tok = tokens(); tok; tok = tok->next()) {
if (tok->str() == "{" && isClassStructUnionEnumStart(tok)) {
for (const Token* tok2 = tok->next(); tok2 != tok->link(); tok2 = tok2->next()) {
if (tok2->str() == "{")
tok2 = tok2->link();
else if (tok2->isKeyword() && nonGlobalKeywords.count(tok2->str()) && !Token::Match(tok2->tokAt(-2), "operator %str%"))
syntaxError(tok2, "keyword '" + tok2->str() + "' is not allowed in class/struct/union/enum scope");
}
}
}

// case keyword must be inside switch
for (const Token *tok = tokens(); tok; tok = tok->next()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(c*8s){}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v(){union{a i;for(i=0;!i;);};}