This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/71912] New: flexible array in union
- From: "drepper.fsp+rhbz at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sun, 17 Jul 2016 15:48:53 +0000
- Subject: [Bug c++/71912] New: flexible array in union
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71912
Bug ID: 71912
Summary: flexible array in union
Product: gcc
Version: 7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: drepper.fsp+rhbz at gmail dot com
Target Milestone: ---
I haven't researched in detail what the accepted wisdom about this code is but
at the very least it is completely unnecessary to reject it, as the code shows.
Code like this is actually from an actual project of mine.
Take the code below. gcc 6.1 and also the current trunk reject the code
because:
v.cc:22:14: error: flexible array member ‘xyyzy::<anonymous union>::<anonymous
struct>::s’ not at end of ‘struct xyyzy’
char s[];
^
v.cc:25:14: note: next member ‘double xyyzy::<anonymous union>::<anonymous
struct>::a’ declared here
double d;
^
v.cc:18:8: note: in the definition of ‘struct xyyzy’
struct xyyzy {
^~~~~
Clearly, the array 's' is not followed by 'a' in anything but a syntactic way.
The compiler does not reject the use of flexible arrays like this when the
types are defined separately, as exampled of type 'baz' shows.
If the rejection is done deliberately at the very least the message must be
fixed but I would also like to see a justification.
NB: the same code compiles fine in C. This is why I added all the unnecessary
'struct'.
struct foo {
int a;
char s[];
};
struct bar {
double d;
char t[];
};
struct baz {
union {
struct foo f;
struct bar b;
} u;
};
struct xyyzy {
union {
struct {
int a;
char s[];
} f;
struct {
double d;
char t[];
} b;
} u;
};
struct baz b;
struct xyyzy x;