File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -1254,6 +1254,18 @@ Parser::DeclGroupPtrTy Parser::ParseDeclarationOrFunctionDefinition(
12541254 Actions.getASTContext ().getSourceManager ());
12551255 });
12561256
1257+ if (DS->getStorageClassSpec () != DeclSpec::SCS_unspecified) {
1258+ // Check if the next token starts a class/struct/union/enum declaration
1259+ if (Tok.isOneOf (tok::kw_class, tok::kw_struct, tok::kw_union, tok::kw_enum)) {
1260+ // Emit an error: storage class specifiers are not allowed before class declarations
1261+ Diag (DS->getStorageClassSpecLoc (), diag::err_storage_class_before_class_decl)
1262+ << DeclSpec::getSpecifierName (DS->getStorageClassSpec ());
1263+
1264+ // Optionally, consume the storage class specifier to continue parsing
1265+ DS->ClearStorageClassSpecs ();
1266+ }
1267+ }
1268+
12571269 if (DS) {
12581270 return ParseDeclOrFunctionDefInternal (Attrs, DeclSpecAttrs, *DS, AS);
12591271 } else {
You can’t perform that action at this time.
0 commit comments