简体   繁体   中英

vector<unique_ptr> gives troubles

I have short code as below:

#include <memory>
#include <vector>
#include <tuple>
using namespace std;

struct A
{
    A() {}
    vector<unique_ptr<int>> m; 
    // Change the above line to "unique_ptr<int> m;" removes the compilation error
    // Or add a line "A(A const&) = delete;" removes the compilation error also
};

struct B
{
    tuple<A> t;
};

int main()
{
    A a;
    B b;
    return 0;
}

VC2013 NOV CTP compiler gives errors:

error C2280: 'std::unique_ptr<int,std::default_delete<_Ty>>::unique_ptr(const std::unique_ptr<_Ty,std::default_delete<_Ty>> &)' : attempting to reference a deleted function xmemory0   593

Is this a compiler bug or code bug?

This was a bug in Visual Studio; according to @Gonmator's comment it's been fixed as of VS2013 Update 1.

It might have been similar to reported bugs such as
https://connect.microsoft.com/VisualStudio/feedback/details/801826/std-tuple-with-rvalue-references-not-working-if-clr-enabled
or
https://connect.microsoft.com/VisualStudio/feedback/details/891428/c-std-pair-has-no-default-move-constructor
— apparently MSVC has had several residual bugs involving "move semantics + std::tuple".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM