Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

implicit copy/move constructors

0 views
Skip to first unread message

Gene Bushuyev

unread,
Aug 16, 2010, 2:49:00 PM8/16/10
to
I've been testing rvalues in gcc 4.5 and VC 2010 and noticed they both
generated implicit copy constructors even though I provided custom
move constructors, which led to some surprises before I found that. Is
that conforming to the latest C++0x? I kind of expected the other ctor
to be suppressed by providing the user defined copy/move ctor.

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Daniel Krügler

unread,
Aug 16, 2010, 10:30:21 PM8/16/10
to
On 16 Aug., 20:49, Gene Bushuyev <publicfil...@gbresearch.com> wrote:
> I've been testing rvalues in gcc 4.5 and VC 2010 and noticed they both
> generated implicit copy constructors even though I provided custom
> move constructors, which led to some surprises before I found that. Is
> that conforming to the latest C++0x? I kind of expected the other ctor
> to be suppressed by providing the user defined copy/move ctor.

Its not the fault of the implementations: The rules had been
changed slightly rather recently. According to the most recent
draft a user-declared move-constructor (assignment operator)
prevents an implicitly declared copy-constructor (assignment
operator) and vice versa. Note that an explicitly defaulted
or deleted special member function is also a user-declaration,
e.g.:

struct X {
X(const X&) = default; // No implicitly declared move-
// constructor
X& operator=(const X&) = delete; // No implicitly declared
// move-assignment operator
};

HTH & Greetings from Bremen,

Daniel Krügler

Mathias Gaunard

unread,
Aug 16, 2010, 10:34:37 PM8/16/10
to
On Aug 16, 7:49 pm, Gene Bushuyev <publicfil...@gbresearch.com> wrote:
> I've been testing rvalues in gcc 4.5 and VC 2010 and noticed they both
> generated implicit copy constructors even though I provided custom
> move constructors, which led to some surprises before I found that. Is
> that conforming to the latest C++0x?

Yes.


> I kind of expected the other ctor
> to be suppressed by providing the user defined copy/move ctor.

I don't see any reasoning why that should be the case.
Objects are copyable by default, irrelevant to whether you special-
case the rvalue case or not.

If you want to disable the lvalue case, delete the overload.

Mathias Gaunard

unread,
Aug 17, 2010, 1:45:32 PM8/17/10
to
On Aug 17, 3:34 am, Mathias Gaunard <loufo...@gmail.com> wrote:
> On Aug 16, 7:49 pm, Gene Bushuyev <publicfil...@gbresearch.com> wrote:
>
> > I've been testing rvalues in gcc 4.5 and VC 2010 and noticed they both
> > generated implicit copy constructors even though I provided custom
> > move constructors, which led to some surprises before I found that. Is
> > that conforming to the latest C++0x?
>
> Yes.

Please ignore, this, I wasn't aware this had been changed.

0 new messages