https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120353
Bug ID: 120353
Summary: Flex array struct referenced in the middle via type
alias of forward declaration is not reported by
-Wflex-array-member-not-at-end option
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: alansnape3058 at gmail dot com
Target Milestone: ---
Details and comparison with Clang in https://godbolt.org/z/P1aYbY1j3
For a struct containing a flexible array member, if one of its type aliases is
defined with its forward declaration, referencing this alias to define a member
in the middle of another struct will not be reported by option
-Wflex-array-member-not-at-end.
```
typedef struct X XX;
struct X {
int length;
int a[];
};
struct Q {
XX x;
int plug;
};
```
In this example, a type alias `XX` is defined for `struct X` via its forward
declaration. Then, `struct X` is defined as a flexible array struct. Finally,
the type alias `XX` is referenced in `struct Q` to define a member in the
middle. This leads to a flexible array member in the middle problem. However,
this problem is not reported by the latest version of GCC.
Even if there are other re-definitions of `XX` below `struct X`, when there is
a definition above the struct, this problem will not be reported.
```
typedef struct X XX; // First definition above struct X
struct X {
int length;
int a[];
};
typedef struct X XX; // Redefinition below struct X
struct Q {
XX x; // Also not reported
int plug;
};
```