Why is the copy destination not deleted when the transfer is declared?

struct A { A(int x) : n(x) {} A(A&&) {} A& operator =(A&&) { return *this; } int n; }; int main() { A a(1), b(2); a = b; if (2 == an) { // It SHOULD go here! } } 

According to C ++ 12.8.7 standard:

If the class definition declares a move constructor or transfers an operator assignment, an implicitly declared copy constructor is defined as excluded;

and 12.8.18

If the class definition declares a move constructor or transfers an operator assignment, the implicitly declared copy assignment operator is determined as deleted;

The operator a = b; should cause a compiler error. However, my compiler (VC ++ 2013 RC) accepts it and invokes an implicit copy job instead.

Is this a compiler error?

Update:

I presented this problem as a bug in microsoft .

+7
c ++ compiler-construction copy-constructor c ++ 11 deleted-functions
source share
1 answer

This seems like a compiler error.

Since you have defined the operator assignment operator provided by the user, the copy destination operator must be implicitly defined as remote (as specified in 12.8.18). This behavior is exhibited by other compilers (e.g. gcc).

+2
source share

All Articles