Skip to content

Commit ab8c853

Browse files
committed
add check logic for auto class type
1 parent ef353b0 commit ab8c853

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

clang/lib/Parse/Parser.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff 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 {

0 commit comments

Comments
 (0)