Does the latest intel c++ compiler support implicit move constructor and move assignment?

773 Views Asked by At

The latest intel C++ compiler is 14.0.1.139 or in intel parallel studio xe 2013 sp1 update 1. I am wondering if it supports implicit move constructor and move assignment. I tested it the following code, it doesn't seem to work.

The related article is here (search move constructor). It said it supports. But I cannot make it.

#include <memory>
#include <iostream>
#include <algorithm>

using namespace std;

class A
{
public:
    unique_ptr<int> m;
};

int main()
{
    A a;
    A b(std::move(a));
}

Compile it on windows as

icl main.cpp /Qstd=c++11

Errors

main.cpp
main.cpp(10): error #373: "std::unique_ptr<_Ty, _Dx>::unique_ptr(const
    std::unique_ptr<_Ty, _Dx>::_Myt &) [with _Ty=int, _Dx=std::default_delete<int>]"
    (declared at line 1447 of "C:\Program Files (x86)\Microsoft Visual Studio
    11.0\VC\include\memory") is inaccessible unique_ptr<int> m;
                                                             ^
detected during implicit generation of "A::A(const A &)" at line 16
compilation aborted for main.cpp (code 2)

Basically the 2nd line in the main function A b(std::move(a)); is looking for copy constructor A::A(const A &) other than move constructor A::A(const A &&). That is usual when no implicit move constructors are generated. But the compiler said it support implicit move constructor. I am confused. Thanks.

1

There are 1 best solutions below

4
On

Answer 1:

On Windows environment when using Intel C++ compiler with Visual Studio 2010* or 2012*, the C++11 features supported by Visual C++ 2010/2012 are enabled by default. Use "/Qstd=c++11" to turn on the support for all other cases. On Linux or Mac OS X environment use "-std=c++11".

From http://software.intel.com/en-us/articles/c0x-features-supported-by-intel-c-compiler

Answer 2 (guessing because of lack of information): If the flag is set, you must include <algorithm> where std::move is defined.

Answer 3: Your updated code compiles well with GCC and Clang. Maybe you have to define the move constructor explicitly:

#include <memory>
#include <iostream>
#include <algorithm>

using namespace std;

class A
{
public:
    // default constructor
    A()
    {}
    // move constructor
    A(A&& rhs)
    : m(std::move(rhs.m))
    {}

    unique_ptr<int> m;
};

int main()
{
    A a;
    A b(std::move(a));
}