Visual Studio 2013 does not remove the copy constructor when a custom move constructor is provided

I appreciate that the C ++ 11 standard dictates:

If the class definition does not explicitly declare a copy constructor, one is declared implicitly. If a class definition declares a move constructor or a move carry operator, an implicitly declared copy constructor is defined as deleted ; otherwise, it is defined as default.

(actually copied from here )

The following code:

#include <iostream> struct C { int x = 1; C() { } C(C&&) { } }; int main() { const C c; C c2(c); std::cout << cx << " " << c2.x << std::endl; return 0; } 

does not compile on gcc 4.9.0 , but compiles only fine on Visual Studio 2013 ( Compiler Version 18.00.21005.1 for x86 ). Is this another violation of the Visual Studio standard, or am I doing something wrong this time? If this is a violation of the standard, is there a tracking error or any source where this behavior is documented?

+8
c ++ c ++ 11 visual-studio visual-studio-2013
source share
1 answer

You are not doing anything wrong, and your interpretation of the standard is correct. Visual C ++ 2013 does not really follow these rules correctly.

The corresponding error report is here:

A default instance constructor is generated even if a custom move constructor is defined [C ++ 11]

It is marked as Won't Fix , and a comment from the development team:

Visual Studio 2013 does not really fully implement the C ++ 11 rules for managing special member functions and moving operations. We will include a fix for this error in the next major release of Visual Studio.

The good news is that everything works correctly in Visual C ++ 2015 RC. I just checked that your code runs both the compiler and IntelliSense errors. Compiler Diagnostics:

 error C2280: 'C::C(const C &)': attempting to reference a deleted function 

(From what I tested over the past few months, MSVC14 is formed as a pretty good C ++ compiler - many standard compliance issues have been fixed.)

+5
source share

All Articles