[cfe-dev] deprecating copy construction and assignment
Sean Silva
silvas at purdue.edu
Thu Mar 29 14:42:10 PDT 2012
Could someone explain why the second one is move-constructible and
move-assignable while the first one is not?
How does explicitly defaulting the move-constructor and move-assignment
cause A to *not* be move-constructible nor move-assignable, while omitting
them makes A be move-constructible and move-assignable?
--Sean Silva
On Wed, Mar 28, 2012 at 2:28 PM, Howard Hinnant <hhinnant at apple.com> wrote:
> On Mar 28, 2012, at 2:14 PM, David Blaikie wrote:
>
> > On Wed, Mar 28, 2012 at 11:08 AM, Howard Hinnant <hhinnant at apple.com>
> wrote:
> >> In a few instances the implicit definition of a defaulted copy
> constructor and copy assignment operator is deprecated in C++11. E.g.:
> >>
> >> struct A
> >> {
> >> // A(const A&) = default; // deprecated
> >>
> >> // A& operator=(const A&) = default; // deprecated
> >>
> >> ~A();
> >> };
> >>
> >> Should we warn when both -std=c++11 and -Wdeprecated is given?
> >
> > I believe we should, yes - just that no one's gotten around to
> > implementing this (it's been somewhere on my mental list).
> >
> > Aside: It'd be rather nice if these rules actually implemented the
> > classic "rule of three" (if you implement any of the three you should
> > implement all three - or 5 in C++11) but I don't think the standard
> > wording goes quite that far.
>
> It comes pretty close to the rule of 3:
>
> The implicitly default copy constructor is deprecated if there is a
> user-declared copy assignment or destructor.
>
> The implicitly default copy assignment is deprecated if there is a
> user-declared copy constructor or destructor.
>
> One needs to be more careful with defaulting the move members. It is easy
> to default them and have them get implicitly deleted:
>
> struct member
> {
> member();
> member(const member&);
> member& operator=(const member&);
> ~member();
> };
>
> struct A
> {
> member m_;
>
> A() = default;
> A(const A&) = default;
> A& operator=(const A&) = default;
> A(A&&) = default;
> A& operator=(A&&) = default;
> ~A() = default;
> };
>
> A is neither move constructible nor move assignable. The following is
> probably what was intended:
>
> struct A
> {
> member m_;
>
> A() = default;
> A(const A&) = default;
> A& operator=(const A&) = default;
> ~A() = default;
> };
>
> which, ironically, *is* move constructible and move assignable. :-) But
> I'm not suggesting a warning for this.
>
> Howard
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120329/030aaab5/attachment.html>
More information about the cfe-dev
mailing list