From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 49267 invoked by alias); 22 Oct 2015 15:24:41 -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 49234 invoked by uid 48); 22 Oct 2015 15:24:37 -0000 From: "akju at mailinator dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/68051] New: copy constructor does not copy default initialized union member Date: Thu, 22 Oct 2015 15:24: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: 5.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: akju at mailinator dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: 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 target_milestone 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: 2015-10/txt/msg01866.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68051 Bug ID: 68051 Summary: copy constructor does not copy default initialized union member Product: gcc Version: 5.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: akju at mailinator dot com Target Milestone: --- The assertion at the end of the following code fails erroneously: #include #include struct test { union {int v = 0;}; std::string dummy; }; int main () { test x; x.v = 1; test y = x; assert (y.v == 1); } According to the assembly listing, it seems that the copy construction of y uses the default member initializer of v instead of x.v. This behaviour does not occur if the dummy member is removed causing the struct to be trivially copyable.