From a2561d07f3b6c07de0db312ed32d26c01b429d89 Mon Sep 17 00:00:00 2001 From: Jesse Rosenstock Date: Wed, 29 Jul 2020 14:04:52 +0200 Subject: [PATCH] Remove special-case bit-field width code cbb33f8 restricted allowed bit-field types to int, so this is equivalent for now, but forward-compatible. Fixes FIXME Also move the int type check before parsing the colon. --- src/cc65/declare.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/cc65/declare.c b/src/cc65/declare.c index 48db64e61..b8ad09cfd 100644 --- a/src/cc65/declare.c +++ b/src/cc65/declare.c @@ -681,14 +681,16 @@ static int ParseFieldWidth (Declaration* Decl) return -1; } + if (!IsClassInt (Decl->Type)) { + /* Only integer types may be used for bit-fields */ + Error ("Bit-field has invalid type '%s', must be integral", + GetBasicTypeName (Decl->Type)); + return -1; + } + /* Read the width */ NextToken (); ConstAbsIntExpr (hie1, &Expr); - if (!IsClassInt (Decl->Type)) { - /* Only integer types may be used for bit-fields */ - Error ("Bit-field has invalid type '%s'", GetBasicTypeName (Decl->Type)); - return -1; - } if (SizeOf (Decl->Type) != SizeOf (type_uint)) { /* Only int sized types may be used for bit-fields for now */ @@ -700,20 +702,10 @@ static int ParseFieldWidth (Declaration* Decl) Error ("Negative width in bit-field"); return -1; } - /* FIXME: We should compare with the width of the specified type */ -#if 0 - /* Use is when we really support non-uint16_t bit-fields */ if (Expr.IVal > (long)(SizeOf (Decl->Type) * CHAR_BITS)) { Error ("Width of bit-field exceeds its type"); return -1; } -#else - /* This is what we currenty do */ - if (Expr.IVal > (long)(SizeOf (type_uint) * CHAR_BITS)) { - Error ("Width of bit-field exceeds 16"); - return -1; - } -#endif if (Expr.IVal == 0 && Decl->Ident[0] != '\0') { Error ("Zero width for named bit-field"); return -1;