Bug 72753 - sole flexible array member in a typedef rejected
Summary: sole flexible array member in a typedef rejected
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 7.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
Depends on:
Blocks: flexmembers
  Show dependency treegraph
 
Reported: 2016-07-29 21:37 UTC by Martin Sebor
Modified: 2021-08-27 18:44 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 10.1.0, 9.3.0, 9.4.0
Known to fail: 8.5.0, 9.1.0, 9.2.0
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Sebor 2016-07-29 21:37:11 UTC
The following program defines two structs whose only member is a flexible array.  Such types are invalid and should be rejected.  G++ diagnoses the one defined in the named struct but fails to diagnose the one in the unnamed struct.

$ cat t.C && /build/gcc-trunk-svn/gcc/xgcc -B /build/gcc-trunk-svn/gcc -S -Wall -Wextra -Wpedantic t.C
struct A {
  int a[];
};

typedef struct {
  int a[];
} B;
t.C:2:9: error: flexible array member ‘A::a’ in an otherwise empty ‘struct A’
   int a[];
         ^
t.C:1:8: note: in the definition of ‘struct A’
 struct A {
        ^
Comment 1 Martin Sebor 2016-07-29 21:50:03 UTC
Same problem with an unnamed struct defined via an alias-declaration:

  using S = struct { int a[]; };
Comment 2 Andrew Pinski 2021-08-27 18:44:45 UTC
Fixed for GCC 9.3 and GCC 10+ by the patch which fixed PR 93753.