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 == a.n)
{
// It SHOULD go here!
}
}
As per the C++ standard 12.8.7:
If the class definition declares a move constructor or move assignment operator, the implicitly declared copy constructor is defined as deleted;
and 12.8.18
If the class definition declares a move constructor or move assignment operator, the implicitly declared copy assignment operator is defined as deleted;
The statement a = b;
should trigger a compiler error. However, my compiler (VC++ 2013 RC) accepts it and calls the implicitly-defined copy assignment instead.
Is this a compiler's bug?
Update:
I have submitted this issue as a bug to microsoft.
a = b
wouldn't call the copy constructor, would it? – Telephonya = b
a copy-assignment here? Your quote says the copy-constructor is deleted, not the copy-assignment operator. – Magmaa=b
with GCC, looks like a bug in VC++ to me. The error message from GCC iserror: use of deleted function 'A& A::operator=(const A&)'
andnote: 'A& A::operator=(const A&)' is implicitly declared as deleted because 'A' declares a move constructor or move assignment operator
– Mousseline