This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug middle-end/28865] Structures with a flexible arrray member have wrong .size


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" } };


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]