public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/66583] New: incorrect implicitly-defined move constructor for class with anonymous union and NSDMI
@ 2015-06-18 10:13 jens.maurer at gmx dot net
  2015-06-18 17:00 ` [Bug c++/66583] " daniel.kruegler at googlemail dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: jens.maurer at gmx dot net @ 2015-06-18 10:13 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66583

            Bug ID: 66583
           Summary: incorrect implicitly-defined move constructor for
                    class with anonymous union and NSDMI
           Product: gcc
           Version: 5.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jens.maurer at gmx dot net
  Target Milestone: ---

The following code wrongly prints 0 instead of the correct 1:

$ g++ -std=c++11 union.cc 
$ ./a.out 
0

(reproducible with both 4.9.2 and 5.1.0)


#include <algorithm>
#include <iostream>

struct A {
  A() { };
  A(const A&) { }
};

struct B {
  union {
    int m_1 = 0;
    int m_2;
  };
  A dummy;
};

int main()
{
  B b;
  b.m_1 = 1;
  B c(std::move(b));
  std::cout << c.m_1 << std::endl;
}


The assembly code for B::B(B&&) when compiling unoptimized has this (x86-64):

        movl    (%rdx), %edx
        movl    %edx, (%rax)

Until here, we correctly copy the object representation of the anonymous union
(12.8p16).

        movq    -8(%rbp), %rax
        movl    $0, (%rax)

And then we seem to evaluate the non-static data member initializer for m_1,
which is (obviously) wrong.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/66583] incorrect implicitly-defined move constructor for class with anonymous union and NSDMI
  2015-06-18 10:13 [Bug c++/66583] New: incorrect implicitly-defined move constructor for class with anonymous union and NSDMI jens.maurer at gmx dot net
@ 2015-06-18 17:00 ` daniel.kruegler at googlemail dot com
  2015-10-21  0:35 ` jason at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2015-06-18 17:00 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66583

Daniel Krügler <daniel.kruegler at googlemail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |daniel.kruegler@googlemail.
                   |                            |com

--- Comment #1 from Daniel Krügler <daniel.kruegler at googlemail dot com> ---
The problem seems to exists for the current head gcc HEAD 6.0.0 20150617
(experimental) as well.
>From gcc-bugs-return-489337-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Thu Jun 18 17:09:06 2015
Return-Path: <gcc-bugs-return-489337-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 93743 invoked by alias); 18 Jun 2015 17:09:05 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 93218 invoked by uid 48); 18 Jun 2015 17:08:59 -0000
From: "jason at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/66585] [5/6 Regression] Internal compiler error when initialize field with lambda
Date: Thu, 18 Jun 2015 17:09:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c++
X-Bugzilla-Version: 5.1.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: jason at gcc dot gnu.org
X-Bugzilla-Status: ASSIGNED
X-Bugzilla-Resolution:
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: jason at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: bug_status assigned_to
Message-ID: <bug-66585-4-QOhpx97b0W@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-66585-4@http.gcc.gnu.org/bugzilla/>
References: <bug-66585-4@http.gcc.gnu.org/bugzilla/>
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-06/txt/msg01669.txt.bz2
Content-length: 375

https://gcc.gnu.org/bugzilla/show_bug.cgi?idf585

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |jason at gcc dot gnu.org


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/66583] incorrect implicitly-defined move constructor for class with anonymous union and NSDMI
  2015-06-18 10:13 [Bug c++/66583] New: incorrect implicitly-defined move constructor for class with anonymous union and NSDMI jens.maurer at gmx dot net
  2015-06-18 17:00 ` [Bug c++/66583] " daniel.kruegler at googlemail dot com
@ 2015-10-21  0:35 ` jason at gcc dot gnu.org
  2015-10-21  2:24 ` jason at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: jason at gcc dot gnu.org @ 2015-10-21  0:35 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66583

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2015-10-21
                 CC|                            |jason at gcc dot gnu.org
           Assignee|unassigned at gcc dot gnu.org      |jason at gcc dot gnu.org
     Ever confirmed|0                           |1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/66583] incorrect implicitly-defined move constructor for class with anonymous union and NSDMI
  2015-06-18 10:13 [Bug c++/66583] New: incorrect implicitly-defined move constructor for class with anonymous union and NSDMI jens.maurer at gmx dot net
  2015-06-18 17:00 ` [Bug c++/66583] " daniel.kruegler at googlemail dot com
  2015-10-21  0:35 ` jason at gcc dot gnu.org
@ 2015-10-21  2:24 ` jason at gcc dot gnu.org
  2015-10-21  9:27 ` jason at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: jason at gcc dot gnu.org @ 2015-10-21  2:24 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66583

--- Comment #2 from Jason Merrill <jason at gcc dot gnu.org> ---
Author: jason
Date: Wed Oct 21 02:24:08 2015
New Revision: 229108

URL: https://gcc.gnu.org/viewcvs?rev=229108&root=gcc&view=rev
Log:
        PR c++/66583

        * init.c (innermost_aggr_scope): New.
        (build_field_list): Change uses_unions_p to uses_unions_or_anon_p.
        (sort_mem_initializers): Handle initializers for entire anonymous
        aggregates.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/anon-union1.C
    trunk/gcc/testsuite/g++.dg/ext/anon-struct7.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/init.c


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/66583] incorrect implicitly-defined move constructor for class with anonymous union and NSDMI
  2015-06-18 10:13 [Bug c++/66583] New: incorrect implicitly-defined move constructor for class with anonymous union and NSDMI jens.maurer at gmx dot net
                   ` (2 preceding siblings ...)
  2015-10-21  2:24 ` jason at gcc dot gnu.org
@ 2015-10-21  9:27 ` jason at gcc dot gnu.org
  2015-10-21  9:28 ` jason at gcc dot gnu.org
  2015-10-22 17:17 ` trippels at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: jason at gcc dot gnu.org @ 2015-10-21  9:27 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66583

--- Comment #3 from Jason Merrill <jason at gcc dot gnu.org> ---
Author: jason
Date: Wed Oct 21 09:27:18 2015
New Revision: 229122

URL: https://gcc.gnu.org/viewcvs?rev=229122&root=gcc&view=rev
Log:
        PR c++/66583

        * init.c (innermost_aggr_scope): New.
        (sort_mem_initializers): Use it.

Added:
    branches/gcc-5-branch/gcc/testsuite/g++.dg/cpp0x/anon-union1.C
Modified:
    branches/gcc-5-branch/gcc/cp/ChangeLog
    branches/gcc-5-branch/gcc/cp/init.c


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/66583] incorrect implicitly-defined move constructor for class with anonymous union and NSDMI
  2015-06-18 10:13 [Bug c++/66583] New: incorrect implicitly-defined move constructor for class with anonymous union and NSDMI jens.maurer at gmx dot net
                   ` (3 preceding siblings ...)
  2015-10-21  9:27 ` jason at gcc dot gnu.org
@ 2015-10-21  9:28 ` jason at gcc dot gnu.org
  2015-10-22 17:17 ` trippels at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: jason at gcc dot gnu.org @ 2015-10-21  9:28 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66583

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED
   Target Milestone|---                         |5.3

--- Comment #4 from Jason Merrill <jason at gcc dot gnu.org> ---
Fixed for 5.3/6.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/66583] incorrect implicitly-defined move constructor for class with anonymous union and NSDMI
  2015-06-18 10:13 [Bug c++/66583] New: incorrect implicitly-defined move constructor for class with anonymous union and NSDMI jens.maurer at gmx dot net
                   ` (4 preceding siblings ...)
  2015-10-21  9:28 ` jason at gcc dot gnu.org
@ 2015-10-22 17:17 ` trippels at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: trippels at gcc dot gnu.org @ 2015-10-22 17:17 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66583

Markus Trippelsdorf <trippels at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |akju at mailinator dot com

--- Comment #5 from Markus Trippelsdorf <trippels at gcc dot gnu.org> ---
*** Bug 68051 has been marked as a duplicate of this bug. ***


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-10-22 17:17 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-18 10:13 [Bug c++/66583] New: incorrect implicitly-defined move constructor for class with anonymous union and NSDMI jens.maurer at gmx dot net
2015-06-18 17:00 ` [Bug c++/66583] " daniel.kruegler at googlemail dot com
2015-10-21  0:35 ` jason at gcc dot gnu.org
2015-10-21  2:24 ` jason at gcc dot gnu.org
2015-10-21  9:27 ` jason at gcc dot gnu.org
2015-10-21  9:28 ` jason at gcc dot gnu.org
2015-10-22 17:17 ` trippels at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).