From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25312 invoked by alias); 3 Sep 2013 04:05:31 -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 25288 invoked by uid 48); 3 Sep 2013 04:05:27 -0000 From: "darrenrjenkins at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/58303] New: C99 union initializers new union members clobber earlier data Date: Tue, 03 Sep 2013 04:05: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.6.2 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: darrenrjenkins at gmail dot com 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 bug_severity priority component assigned_to reporter 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: 2013-09/txt/msg00101.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58303 Bug ID: 58303 Summary: C99 union initializers new union members clobber earlier data Product: gcc Version: 4.6.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: darrenrjenkins at gmail dot com If using C99 initializers on a union, and using different union members. The later members seem to clobber the previous members data. I haven't looked at the standards with respect to this, but it seems wrong. #include typedef struct { int a; int b; } a_t; typedef struct { int c; int d; } b_t; typedef union { a_t a; b_t b; } c_t; void main( int argc, char *argv[] ) { c_t var = { .a.a = 4, .b.d = 7 }; printf( ".a.a = %d .b.d = %d\n", var.a.a, var.b.d ); }