Disallowed empty enums.

This commit is contained in:
acqn
2020-08-07 17:40:40 +08:00
committed by Oliver Schmidt
parent 97065faf1a
commit fe44fe963f

View File

@@ -549,8 +549,8 @@ static SymEntry* ParseEnumDecl (const char* Name)
ident Ident; ident Ident;
long MinConstant = 0; long MinConstant = 0;
unsigned long MaxConstant = 0; unsigned long MaxConstant = 0;
const Type* NewType = type_int; /* new enumerator type */ const Type* NewType = 0; /* new member type */
const Type* MemberType = type_int; /* default enumerator type */ const Type* MemberType = type_int; /* default member type */
/* Accept forward definitions */ /* Accept forward definitions */
if (CurTok.Tok != TOK_LCURLY) { if (CurTok.Tok != TOK_LCURLY) {
@@ -677,6 +677,11 @@ static SymEntry* ParseEnumDecl (const char* Name)
} }
ConsumeRCurly (); ConsumeRCurly ();
/* Check if there have been any members. Error if none */
if (NewType == 0) {
Error ("Empty enum is invalid");
}
/* This evaluates the underlying type of the whole enum */ /* This evaluates the underlying type of the whole enum */
MemberType = GetEnumeratorType (MinConstant, MaxConstant, 0); MemberType = GetEnumeratorType (MinConstant, MaxConstant, 0);
if (MemberType == 0) { if (MemberType == 0) {