https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121209
Bug ID: 121209 Summary: Taking the composite type twice of two structure, union, or enumerated types yields different results Product: gcc Version: 16.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: luigighiron at gmail dot com Target Milestone: --- The following two programs demonstrate how GCC will compute the composite type of two types differently when done multiple times: struct A{int h;}; int main(){ extern struct A x,y; struct A{int h;}; extern struct A x,y; typedef typeof(x)T; typedef typeof(y)T; } typedef enum E{h}A; int main(){ typedef enum E{h}B; extern A x; extern B x; extern B y; extern A y; typedef typeof(x)T; typedef typeof(y)T; } In the first program, x and y are both declared with a structure type then redeclared with another structure type. The declaration of x and y use the same structure type, and the redeclaration of x and y use the same structure type. Intuitively, x and y should have the same type but GCC does not give them the same type as evidenced by the second declaration of T generating an error. The second program does something similar but instead of structure types it uses enumerated types, and the order of declarations with y is reversed. Intuitively, the order of these declarations shouldn't matter but GCC does not agree as evidenced by the second declaration of T generating an error. Swapping the order of the declarations of y will make the program work, unlike with structure or union types.