public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/55098] New: c++11: move constructor doesn't run at all (but with a hammer)
@ 2012-10-27 14:39 lisp2d at lisp2d dot net
  2012-10-27 15:01 ` [Bug c++/55098] " lisp2d at lisp2d dot net
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: lisp2d at lisp2d dot net @ 2012-10-27 14:39 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55098

             Bug #: 55098
           Summary: c++11: move constructor doesn't run at all (but with a
                    hammer)
    Classification: Unclassified
           Product: gcc
           Version: 4.7.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: lisp2d@lisp2d.net


standard says:
A non-template constructor for class X is a move constructor if its first
parameter is of type X&&, const
X&&, volatile X&&, or const volatile X&&, and either there are no other
parameters or else all other
parameters have default arguments (8.3.6). [ Example: Y::Y(Y&&) is a move
constructor.
struct Y {
Y(const Y&);
Y(Y&&);
};
extern Y f(int);
Y d(f(1)); // calls Y(Y&&)
Y e = d; // calls Y(const Y&)

test.cpp:
#include    <iostream>
class    A{
public:
int    a;
explicit    A(int    const    &    x):a{x}{std::cout<<"A(int const
&)"<<std::endl;}
A(A    const    &    x):a{x.a}{std::cout<<"A(A const &)"<<std::endl;}
A(A    &&    x):a{x.a}{std::cout<<"A(A &&)"<<std::endl;}
A operator    +(A    const & x){std::cout<<"A+(A const &)"<<std::endl;return
A{a + x.a};}
A operator    +(A    && x){std::cout<<"A+(A &&)"<<std::endl;return A{a + x.a};}
};

extern A    f(int    const    &    x);

int    main(int,char**){
std::cout<<"---"<<std::endl;
A x(f(0));
std::cout<<"---"<<std::endl;
A    y(f(1)+f(2));
std::cout<<"---"<<std::endl;
}

A    f(int    const    &    x){
    A    tmp{x};
    ++    (tmp.a);
    return    tmp;}

result:
---
A(int const &)
---
A(int const &)
A(int const &)
A+(A &&)
A(int const &)
---

The hammer is:
A x(static_cast<A &&>(f(0)));
A y(static_cast<A &&>(f(1)+f(2)));


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

* [Bug c++/55098] c++11: move constructor doesn't run at all (but with a hammer)
  2012-10-27 14:39 [Bug c++/55098] New: c++11: move constructor doesn't run at all (but with a hammer) lisp2d at lisp2d dot net
@ 2012-10-27 15:01 ` lisp2d at lisp2d dot net
  2012-10-27 15:05 ` redi at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: lisp2d at lisp2d dot net @ 2012-10-27 15:01 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55098

--- Comment #1 from Lisp2D <lisp2d at lisp2d dot net> 2012-10-27 15:01:42 UTC ---
May be it is optimisation, but without instruction and with side effects.


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

* [Bug c++/55098] c++11: move constructor doesn't run at all (but with a hammer)
  2012-10-27 14:39 [Bug c++/55098] New: c++11: move constructor doesn't run at all (but with a hammer) lisp2d at lisp2d dot net
  2012-10-27 15:01 ` [Bug c++/55098] " lisp2d at lisp2d dot net
@ 2012-10-27 15:05 ` redi at gcc dot gnu.org
  2012-10-27 15:22 ` lisp2d at lisp2d dot net
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2012-10-27 15:05 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55098

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-10-27 15:04:48 UTC ---
See http://en.wikipedia.org/wiki/Return_value_optimization

Use -fno-elide-constructors to disable constructor elision


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

* [Bug c++/55098] c++11: move constructor doesn't run at all (but with a hammer)
  2012-10-27 14:39 [Bug c++/55098] New: c++11: move constructor doesn't run at all (but with a hammer) lisp2d at lisp2d dot net
  2012-10-27 15:01 ` [Bug c++/55098] " lisp2d at lisp2d dot net
  2012-10-27 15:05 ` redi at gcc dot gnu.org
@ 2012-10-27 15:22 ` lisp2d at lisp2d dot net
  2012-10-27 15:24 ` lisp2d at lisp2d dot net
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: lisp2d at lisp2d dot net @ 2012-10-27 15:22 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55098

Lisp2D <lisp2d at lisp2d dot net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |

--- Comment #3 from Lisp2D <lisp2d at lisp2d dot net> 2012-10-27 15:22:18 UTC ---
My opinion is to enable elide-constructors in -sdt=c++11.
Programers in this standard use own move-constructors with own-side effects.


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

* [Bug c++/55098] c++11: move constructor doesn't run at all (but with a hammer)
  2012-10-27 14:39 [Bug c++/55098] New: c++11: move constructor doesn't run at all (but with a hammer) lisp2d at lisp2d dot net
                   ` (2 preceding siblings ...)
  2012-10-27 15:22 ` lisp2d at lisp2d dot net
@ 2012-10-27 15:24 ` lisp2d at lisp2d dot net
  2012-10-27 15:46 ` lisp2d at lisp2d dot net
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: lisp2d at lisp2d dot net @ 2012-10-27 15:24 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55098

--- Comment #4 from Lisp2D <lisp2d at lisp2d dot net> 2012-10-27 15:24:06 UTC ---
(In reply to comment #3)
> My opinion is to enable elide-constructors in -sdt=c++11.
> Programers in this standard use own move-constructors with own-side effects.

My opinion is to disable elide-constructors in -sdt=c++11.
Programers in this standard use own move-constructors with own-side effects.


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

* [Bug c++/55098] c++11: move constructor doesn't run at all (but with a hammer)
  2012-10-27 14:39 [Bug c++/55098] New: c++11: move constructor doesn't run at all (but with a hammer) lisp2d at lisp2d dot net
                   ` (3 preceding siblings ...)
  2012-10-27 15:24 ` lisp2d at lisp2d dot net
@ 2012-10-27 15:46 ` lisp2d at lisp2d dot net
  2012-10-27 15:54 ` redi at gcc dot gnu.org
  2012-10-27 16:03 ` redi at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: lisp2d at lisp2d dot net @ 2012-10-27 15:46 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55098

--- Comment #5 from Lisp2D <lisp2d at lisp2d dot net> 2012-10-27 15:46:39 UTC ---
OK. Right path is: DON'T return anything.


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

* [Bug c++/55098] c++11: move constructor doesn't run at all (but with a hammer)
  2012-10-27 14:39 [Bug c++/55098] New: c++11: move constructor doesn't run at all (but with a hammer) lisp2d at lisp2d dot net
                   ` (4 preceding siblings ...)
  2012-10-27 15:46 ` lisp2d at lisp2d dot net
@ 2012-10-27 15:54 ` redi at gcc dot gnu.org
  2012-10-27 16:03 ` redi at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2012-10-27 15:54 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55098

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-10-27 15:54:21 UTC ---
(In reply to comment #4)
> My opinion is to disable elide-constructors in -sdt=c++11.

This is nothing new in C++11, the same applies to copy constructors in C++98,
and changing it would make a huge number of programs run slower.  Copy elision
is a Good Thing.  This has been discussed several times in several places and
isn't going to change.

> Programers in this standard use own move-constructors with own-side effects.

No they don't, not if they understand C++.

Don't rely on side effects in copy/move constructors.


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

* [Bug c++/55098] c++11: move constructor doesn't run at all (but with a hammer)
  2012-10-27 14:39 [Bug c++/55098] New: c++11: move constructor doesn't run at all (but with a hammer) lisp2d at lisp2d dot net
                   ` (5 preceding siblings ...)
  2012-10-27 15:54 ` redi at gcc dot gnu.org
@ 2012-10-27 16:03 ` redi at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2012-10-27 16:03 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55098

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-10-27 16:03:17 UTC ---
(In reply to comment #2)
> See http://en.wikipedia.org/wiki/Return_value_optimization
> Use -fno-elide-constructors to disable constructor elision

And also http://en.wikipedia.org/wiki/Copy_elision which says "It is generally
not recommended to disable this important optimization."


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

end of thread, other threads:[~2012-10-27 16:03 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-27 14:39 [Bug c++/55098] New: c++11: move constructor doesn't run at all (but with a hammer) lisp2d at lisp2d dot net
2012-10-27 15:01 ` [Bug c++/55098] " lisp2d at lisp2d dot net
2012-10-27 15:05 ` redi at gcc dot gnu.org
2012-10-27 15:22 ` lisp2d at lisp2d dot net
2012-10-27 15:24 ` lisp2d at lisp2d dot net
2012-10-27 15:46 ` lisp2d at lisp2d dot net
2012-10-27 15:54 ` redi at gcc dot gnu.org
2012-10-27 16:03 ` redi 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).