1
0
mirror of https://github.com/cc65/cc65.git synced 2024-09-27 04:54:54 +00:00

A structure with a flexible array member shall not be a member of a structure or an element of an array according to the ISO C Standard.

This commit is contained in:
acqn 2023-09-18 15:44:58 +08:00
parent dd833125a8
commit fc603129da
3 changed files with 30 additions and 0 deletions

View File

@ -515,6 +515,13 @@ static void CheckArrayElementType (Type* DataType)
if (!IsTypeVoid (T) || IS_Get (&Standard) != STD_CC65) {
Error ("Array of 0-size element type '%s'", GetFullTypeName (T));
}
} else {
if (IsTypeStruct (T)) {
SymEntry* TagEntry = GetESUTagSym (T);
if (TagEntry && SymHasFlexibleArrayMember (TagEntry)) {
Error ("Invalid use of struct with flexible array member");
}
}
}
} else {
++T;
@ -1193,6 +1200,9 @@ static SymEntry* ParseStructSpec (const char* Name, unsigned* DSFlags)
if (TagEntry && SymHasFlexibleArrayMember (TagEntry)) {
Field->Flags |= SC_HAVEFAM;
Flags |= SC_HAVEFAM;
if (IsTypeStruct (Decl.Type)) {
Error ("Invalid use of struct with flexible array member");
}
}
}

View File

@ -0,0 +1,11 @@
/* Bug #2016 - cc65 erroneously allows struct fields that are structs with flexible array members */
typedef struct x {
int a;
int b[]; /* Ok: Flexible array member can be last */
} x;
struct y {
x x; /* Not ok: Contains flexible array member */
int a;
};

View File

@ -0,0 +1,9 @@
/* Bug #2017 - cc65 erroneously allows arrays of structs with flexible array members */
struct z {
int a;
int c;
int b[];
};
struct z y[3]; /* Should be an error */