This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/28865] Structures with a flexible arrray member have wrong .size
- From: "jakub at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 13 Jan 2014 16:46:54 +0000
- Subject: [Bug middle-end/28865] Structures with a flexible arrray member have wrong .size
- Auto-submitted: auto-generated
- References: <bug-28865-4 at http dot gcc dot gnu dot org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28865
--- Comment #22 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
But the glibc headers case you're mentioning wasn't initializing the flexible
array members, right? (Or even initialization with {} initializer is fine I
guess). I mean, while C doesn't allow it, if you don't initialize the flexible
array member followed by something else, it should still work fine as if it was
a zero-sized array. But even in the struct A { struct B { int a; char b[]; };
int c; }; case, I'd say we should error when trying to initialize b to
something non-empty, because we shouldn't be changing the types (thus offsets
in the type fields, type sizes etc.) based on the initializer, only DECL_SIZE
can.
So IMHO we should accept:
struct A { int a; char b[]; };
struct B { struct A a; int c; } b;
struct A p[24];
struct B c = { { 5, {} }, 6 };
struct A q[2] = { { 5, {} }, { 6, {} } };
but reject:
struct B d = { { 1, { 2 } }, 3 };
struct B e = { { 2, "abc" }, 4 };
struct A r[2] = { { 5, "a" }, { 6, "b" } };