std::move required on return of std::unique

I have a function that returns a unique_ptr as follows:

std::unique_ptr<MyClass> createMyClass( ... )
{
    std::unique_ptr<MyClass> my_unique_ptr;
    // Some code that populates my_unique_ptr
    return my_unique_ptr;
}

This function compiles with recent versions of GCC and Clang with -std=c++14, but the Intel compiler (icpc 15.0.3 20150408) complains that default_delete is inaccessible ("error #373"). If I replace the return statement with

    return std::move(my_unique_ptr);

then the Intel compiler is able to compile the code. I was under the impression that copy elision applies at function returns, so std::move is superfluous. Why does Intel want an explicit std::move?

I am on OS X Mavericks, so Intel is linking against libc++, if that matters.

链接地址: http://www.djcxy.com/p/59682.html

上一篇: ptr行为,同时通过函数

下一篇: std :: move需要返回std :: unique