mirror of
https://github.com/cc65/cc65.git
synced 2024-06-07 23:29:39 +00:00
Fixed empty declarations in structs/unions.
This commit is contained in:
parent
0eb38770bd
commit
5332eeecc2
|
@ -983,33 +983,36 @@ static SymEntry* ParseUnionSpec (const char* Name, unsigned* DSFlags)
|
||||||
/* Check for a bit-field declaration */
|
/* Check for a bit-field declaration */
|
||||||
FieldWidth = ParseFieldWidth (&Decl);
|
FieldWidth = ParseFieldWidth (&Decl);
|
||||||
|
|
||||||
/* Ignore zero sized bit fields in a union */
|
/* Check for fields without names */
|
||||||
if (FieldWidth == 0) {
|
|
||||||
goto NextMember;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check for fields without a name */
|
|
||||||
if (Decl.Ident[0] == '\0') {
|
if (Decl.Ident[0] == '\0') {
|
||||||
/* In cc65 mode, we allow anonymous structs/unions within
|
if (FieldWidth < 0) {
|
||||||
** a union.
|
/* In cc65 mode, we allow anonymous structs/unions within
|
||||||
*/
|
** a union.
|
||||||
if (IS_Get (&Standard) >= STD_CC65 && IsClassStruct (Decl.Type)) {
|
*/
|
||||||
/* This is an anonymous struct or union */
|
SymEntry* TagEntry;
|
||||||
AnonFieldName (Decl.Ident, GetBasicTypeName (Decl.Type), UnionTagEntry->V.S.ACount);
|
if (IS_Get (&Standard) >= STD_CC65 &&
|
||||||
|
IsClassStruct (Decl.Type) &&
|
||||||
|
(TagEntry = GetESUTagSym (Decl.Type)) &&
|
||||||
|
SymHasAnonName (TagEntry)) {
|
||||||
|
/* This is an anonymous struct or union */
|
||||||
|
AnonFieldName (Decl.Ident, GetBasicTypeName (Decl.Type), UnionTagEntry->V.S.ACount);
|
||||||
|
|
||||||
/* Ignore CVR qualifiers */
|
/* Ignore CVR qualifiers */
|
||||||
if (IsQualConst (Decl.Type) || IsQualVolatile (Decl.Type) || IsQualRestrict (Decl.Type)) {
|
if (IsQualConst (Decl.Type) || IsQualVolatile (Decl.Type) || IsQualRestrict (Decl.Type)) {
|
||||||
Warning ("Anonymous %s qualifiers are ignored", GetBasicTypeName (Decl.Type));
|
Warning ("Anonymous %s qualifiers are ignored", GetBasicTypeName (Decl.Type));
|
||||||
Decl.Type[0].C &= ~T_QUAL_CVR;
|
Decl.Type[0].C &= ~T_QUAL_CVR;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* A non bit-field without a name is legal but useless */
|
||||||
|
Warning ("Declaration does not declare anything");
|
||||||
|
|
||||||
|
goto NextMember;
|
||||||
}
|
}
|
||||||
} else {
|
} else if (FieldWidth > 0) {
|
||||||
/* A non bit-field without a name is legal but useless */
|
/* A bit-field without a name will get an anonymous one */
|
||||||
Warning ("Declaration does not declare anything");
|
AnonName (Decl.Ident, "bit-field");
|
||||||
}
|
}
|
||||||
}
|
} else if (IsIncompleteType (Decl.Type)) {
|
||||||
|
|
||||||
/* Check for incomplete types including 'void' */
|
|
||||||
if (IsIncompleteType (Decl.Type)) {
|
|
||||||
Error ("Field '%s' has incomplete type '%s'",
|
Error ("Field '%s' has incomplete type '%s'",
|
||||||
Decl.Ident,
|
Decl.Ident,
|
||||||
GetFullTypeName (Decl.Type));
|
GetFullTypeName (Decl.Type));
|
||||||
|
@ -1020,6 +1023,11 @@ static SymEntry* ParseUnionSpec (const char* Name, unsigned* DSFlags)
|
||||||
Flags |= SC_HAVECONST;
|
Flags |= SC_HAVECONST;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Ignore zero sized bit fields in a union */
|
||||||
|
if (FieldWidth == 0) {
|
||||||
|
goto NextMember;
|
||||||
|
}
|
||||||
|
|
||||||
/* Handle sizes */
|
/* Handle sizes */
|
||||||
FieldSize = SizeOf (Decl.Type);
|
FieldSize = SizeOf (Decl.Type);
|
||||||
if (FieldSize > UnionSize) {
|
if (FieldSize > UnionSize) {
|
||||||
|
@ -1180,36 +1188,17 @@ static SymEntry* ParseStructSpec (const char* Name, unsigned* DSFlags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Apart from the above, a bit field with width 0 is not processed
|
|
||||||
** further.
|
|
||||||
*/
|
|
||||||
if (FieldWidth == 0) {
|
|
||||||
goto NextMember;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check if this field is a flexible array member, and
|
|
||||||
** calculate the size of the field.
|
|
||||||
*/
|
|
||||||
if (IsTypeArray (Decl.Type) && GetElementCount (Decl.Type) == UNSPECIFIED) {
|
|
||||||
/* Array with unspecified size */
|
|
||||||
if (StructSize == 0) {
|
|
||||||
Error ("Flexible array member cannot be first struct field");
|
|
||||||
}
|
|
||||||
FlexibleMember = 1;
|
|
||||||
Flags |= SC_HAVEFAM;
|
|
||||||
|
|
||||||
/* Assume zero for size calculations */
|
|
||||||
SetElementCount (Decl.Type, FLEXIBLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check for fields without names */
|
/* Check for fields without names */
|
||||||
if (Decl.Ident[0] == '\0') {
|
if (Decl.Ident[0] == '\0') {
|
||||||
if (FieldWidth < 0) {
|
if (FieldWidth < 0) {
|
||||||
/* In cc65 mode, we allow anonymous structs/unions within
|
/* In cc65 mode, we allow anonymous structs/unions within
|
||||||
** a struct.
|
** a struct.
|
||||||
*/
|
*/
|
||||||
if (IS_Get (&Standard) >= STD_CC65 && IsClassStruct (Decl.Type)) {
|
SymEntry* TagEntry;
|
||||||
|
if (IS_Get (&Standard) >= STD_CC65 &&
|
||||||
|
IsClassStruct (Decl.Type) &&
|
||||||
|
(TagEntry = GetESUTagSym (Decl.Type)) &&
|
||||||
|
SymHasAnonName (TagEntry)) {
|
||||||
/* This is an anonymous struct or union */
|
/* This is an anonymous struct or union */
|
||||||
AnonFieldName (Decl.Ident, GetBasicTypeName (Decl.Type), StructTagEntry->V.S.ACount);
|
AnonFieldName (Decl.Ident, GetBasicTypeName (Decl.Type), StructTagEntry->V.S.ACount);
|
||||||
|
|
||||||
|
@ -1221,18 +1210,34 @@ static SymEntry* ParseStructSpec (const char* Name, unsigned* DSFlags)
|
||||||
} else {
|
} else {
|
||||||
/* A non bit-field without a name is legal but useless */
|
/* A non bit-field without a name is legal but useless */
|
||||||
Warning ("Declaration does not declare anything");
|
Warning ("Declaration does not declare anything");
|
||||||
|
|
||||||
|
goto NextMember;
|
||||||
}
|
}
|
||||||
} else {
|
} else if (FieldWidth > 0) {
|
||||||
/* A bit-field without a name will get an anonymous one */
|
/* A bit-field without a name will get an anonymous one */
|
||||||
AnonName (Decl.Ident, "bit-field");
|
AnonName (Decl.Ident, "bit-field");
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
/* Check if this field is a flexible array member, and
|
||||||
|
** calculate the size of the field.
|
||||||
|
*/
|
||||||
|
if (IsTypeArray (Decl.Type) && GetElementCount (Decl.Type) == UNSPECIFIED) {
|
||||||
|
/* Array with unspecified size */
|
||||||
|
if (StructSize == 0) {
|
||||||
|
Error ("Flexible array member cannot be first struct field");
|
||||||
|
}
|
||||||
|
FlexibleMember = 1;
|
||||||
|
Flags |= SC_HAVEFAM;
|
||||||
|
|
||||||
/* Check for incomplete types including 'void' */
|
/* Assume zero for size calculations */
|
||||||
if (IsIncompleteType (Decl.Type)) {
|
SetElementCount (Decl.Type, FLEXIBLE);
|
||||||
Error ("Field '%s' has incomplete type '%s'",
|
}
|
||||||
Decl.Ident,
|
|
||||||
GetFullTypeName (Decl.Type));
|
if (IsIncompleteType (Decl.Type)) {
|
||||||
|
Error ("Field '%s' has incomplete type '%s'",
|
||||||
|
Decl.Ident,
|
||||||
|
GetFullTypeName (Decl.Type));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check for const types */
|
/* Check for const types */
|
||||||
|
@ -1240,6 +1245,13 @@ static SymEntry* ParseStructSpec (const char* Name, unsigned* DSFlags)
|
||||||
Flags |= SC_HAVECONST;
|
Flags |= SC_HAVECONST;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Apart from the above, a bit field with width 0 is not processed
|
||||||
|
** further.
|
||||||
|
*/
|
||||||
|
if (FieldWidth == 0) {
|
||||||
|
goto NextMember;
|
||||||
|
}
|
||||||
|
|
||||||
/* Add a field entry to the table */
|
/* Add a field entry to the table */
|
||||||
if (FieldWidth > 0) {
|
if (FieldWidth > 0) {
|
||||||
/* Full bytes have already been added to the StructSize,
|
/* Full bytes have already been added to the StructSize,
|
||||||
|
|
|
@ -5,6 +5,11 @@
|
||||||
unsigned failures;
|
unsigned failures;
|
||||||
|
|
||||||
struct X {
|
struct X {
|
||||||
|
const int; /* Useless empty declaration */
|
||||||
|
const void; /* Useless empty declaration */
|
||||||
|
const struct U; /* Useless(?) declaration */
|
||||||
|
const struct V { int a; }; /* Useless(?) declaration */
|
||||||
|
|
||||||
const struct { /* Qualifier ignored in cc65 */
|
const struct { /* Qualifier ignored in cc65 */
|
||||||
int a;
|
int a;
|
||||||
};
|
};
|
||||||
|
@ -14,6 +19,11 @@ struct X {
|
||||||
};
|
};
|
||||||
|
|
||||||
union Y {
|
union Y {
|
||||||
|
const int; /* Useless empty declaration */
|
||||||
|
const void; /* Useless empty declaration */
|
||||||
|
const union W; /* Useless(?) declaration */
|
||||||
|
const union T { int a; }; /* Useless(?) declaration */
|
||||||
|
|
||||||
const struct { /* Qualifier ignored in cc65 */
|
const struct { /* Qualifier ignored in cc65 */
|
||||||
int a;
|
int a;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user