1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-07 23:29:39 +00:00

Allowed using all integer types including enum and char types to define bit-fields,

but kept the currently behavior that all of them are treated as unsigned int.
This commit is contained in:
acqn 2020-07-26 20:12:59 +08:00 committed by Oliver Schmidt
parent d8184fbe54
commit 7e243e0f2c

View File

@ -684,21 +684,31 @@ static int ParseFieldWidth (Declaration* Decl)
/* 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 ''");
return -1;
}
if (Expr.IVal < 0) {
Error ("Negative width in bit-field");
return -1;
}
if (Expr.IVal > (int) INT_BITS) {
/* 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;
}
if (Expr.IVal == 0 && Decl->Ident[0] != '\0') {
Error ("Zero width for named bit-field");
#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;
}
if (!IsTypeInt (Decl->Type)) {
/* Only integer types may be used for bit-fields */
Error ("Bit-field has invalid type");
#endif
if (Expr.IVal == 0 && Decl->Ident[0] != '\0') {
Error ("Zero width for named bit-field");
return -1;
}