From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19545 invoked by alias); 13 Jan 2014 16:47:00 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 19415 invoked by uid 48); 13 Jan 2014 16:46:55 -0000 From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/28865] Structures with a flexible arrray member have wrong .size Date: Mon, 13 Jan 2014 16:47:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 4.2.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 4.7.4 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-01/txt/msg01379.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28865 --- Comment #22 from Jakub Jelinek --- 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" } };