diff --git a/src/cc65/datatype.c b/src/cc65/datatype.c index ad008cfd3..9efb142ee 100644 --- a/src/cc65/datatype.c +++ b/src/cc65/datatype.c @@ -686,7 +686,10 @@ const Type* GetUnderlyingType (const Type* Type) Internal ("Enum tag type error in GetUnderlyingTypeCode"); } - return ((SymEntry*)Type->A.P)->V.E.Type; + /* If incomplete enum type is used, just return its raw type */ + if (((SymEntry*)Type->A.P)->V.E.Type != 0) { + return ((SymEntry*)Type->A.P)->V.E.Type; + } } return Type; @@ -1246,9 +1249,14 @@ Type* IntPromotion (Type* T) ** to unsigned int. */ return IsSignUnsigned (T) ? type_uint : type_int; - } else { - /* Otherwise, the type is not smaller than int, so leave it alone. */ + } else if (!IsIncompleteESUType (T)) { + /* The type is a complete type not smaller than int, so leave it alone. */ return T; + } else { + /* Otherwise, this is an incomplete enum, and there is expceted to be an error already. + ** Assume int to avoid further errors. + */ + return type_int; } } diff --git a/src/cc65/loadexpr.c b/src/cc65/loadexpr.c index f3a1a6add..07f88acbc 100644 --- a/src/cc65/loadexpr.c +++ b/src/cc65/loadexpr.c @@ -142,6 +142,10 @@ void LoadExpr (unsigned Flags, struct ExprDesc* Expr) BitFieldFullWidthFlags |= CF_UNSIGNED; } } else if ((Flags & CF_TYPEMASK) == 0) { + /* If Expr is an incomplete ESY type, bail out */ + if (IsIncompleteESUType (Expr->Type)) { + return; + } Flags |= TypeOf (Expr->Type); }