Fix recursive struct/union redeclaration with qualifiers
GCC now correctly handles recursive structure/union redeclarations involving qualifiers by checking for consistency after completing the variants.
GCC previously rejected valid recursive redeclarations of structures and unions when qualifiers were involved because consistency checks were performed before the variants were fully processed. This commit fixes the issue by deferring the consistency check until after variant completion, ensuring that the complete structure/union definition is available. This resolves a bug that prevented correct code from compiling.
In Details
The bug occurs in c-decl.cc, within the finish_struct function. The check for consistency was being done before the variants were completed, leading to false negatives. This commit defers that check. Qualifiers (const, volatile, restrict) on struct/union members can affect layout and ABI compatibility, so incorrect handling can lead to subtle bugs.
For Context
In C, you can declare structures and unions, which are collections of data members. Sometimes, these structures/unions can refer to themselves recursively. Qualifiers like const can be added to members, affecting how they can be modified. This commit fixes a bug in GCC where recursive structure/union declarations with qualifiers were incorrectly rejected. The compiler now correctly handles these cases, allowing valid code to compile.