File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -108,7 +108,7 @@ static bool isClassStructUnionEnumStart(const Token * tok)
108108 if (!Token::Match (tok->previous (), " class|struct|union|enum|%name%|>|>> {" ))
109109 return false ;
110110 const Token * tok2 = tok->previous ();
111- while (tok2 && !Token::Match (tok2, " class|struct|union|enum|{|}|; " ))
111+ while (tok2 && !Token::Match (tok2, " class|struct|union|enum|{|}|)|;|>|>> " ))
112112 tok2 = tok2->previous ();
113113 return Token::Match (tok2, " class|struct|union|enum" );
114114}
@@ -8776,6 +8776,16 @@ void Tokenizer::findGarbageCode() const
87768776 else if (tok->isKeyword () && nonGlobalKeywords.count (tok->str ()) && !Token::Match (tok->tokAt (-2 ), " operator %str%" ))
87778777 syntaxError (tok, " keyword '" + tok->str () + " ' is not allowed in global scope" );
87788778 }
8779+ for (const Token *tok = tokens (); tok; tok = tok->next ()) {
8780+ if (tok->str () == " {" && isClassStructUnionEnumStart (tok)) {
8781+ for (const Token* tok2 = tok->next (); tok2 != tok->link (); tok2 = tok2->next ()) {
8782+ if (tok2->str () == " {" )
8783+ tok2 = tok2->link ();
8784+ else if (tok2->isKeyword () && nonGlobalKeywords.count (tok2->str ()) && !Token::Match (tok2->tokAt (-2 ), " operator %str%" ))
8785+ syntaxError (tok2, " keyword '" + tok2->str () + " ' is not allowed in class/struct/union scope" );
8786+ }
8787+ }
8788+ }
87798789
87808790 // case keyword must be inside switch
87818791 for (const Token *tok = tokens (); tok; tok = tok->next ()) {
Original file line number Diff line number Diff line change 1+ v(){union{a i;for(i=0;!i;);};}
You can’t perform that action at this time.
0 commit comments