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

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).