From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24078 invoked by alias); 19 Nov 2014 00:31:55 -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 24038 invoked by uid 48); 19 Nov 2014 00:31:51 -0000 From: "jsm28 at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/63944] New: [DR#413] Partial overriding of nonconstant struct/union initializers with designated initializers Date: Wed, 19 Nov 2014 00:31:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 4.9.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: jsm28 at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status keywords bug_severity priority component assigned_to reporter cc Message-ID: 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-11/txt/msg01785.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63944 Bug ID: 63944 Summary: [DR#413] Partial overriding of nonconstant struct/union initializers with designated initializers Product: gcc Version: 4.9.0 Status: UNCONFIRMED Keywords: wrong-code Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: jsm28 at gcc dot gnu.org CC: jakub at gcc dot gnu.org C11 DR#413 has now moved to closed (see N1892). This says that if an initializer (a) initializes a struct or union member of a larger object using an expression of that struct or union type and (b) then uses a designated initializer to override just part of that struct or union initialization, then the overriding does not affect the initialization of the rest of the struct or union. Thus, the following should pass (based on the test in the DR): extern void exit (int); extern void abort (void); typedef struct { int k; int l; int a[2]; } T; typedef struct { int i; T t; } S; T x = {.l = 43, .k = 42, .a[1] = 19, .a[0] = 18 }; int main (void) { S l = { 1, .t = x, .t.l = 41, .t.a[1] = 17}; if (l.t.k == 42) exit (0); else abort (); } Clearly the existing approach for string constants (of splitting them individual characters) won't work here (but is still needed for initializers of objects with static storage duration). This bug is specific to initializers of objects with automatic storage duration; it can apply both to initialization with an expression of struct type, and to initialization with one of union type (in the union case, the override would have to be of just part of a union member, as setting the whole of a union member sets the whole union). I suppose some initializations with such partial overriding need to generate more complicated code - one possibility might be for such partial overriding to replace the initializer for .t with (tmp = x, tmp.l = 41, tmp) for a new temporary variable tmp.