MSVC ++ map <int,list <unique_ptr <test =“”>&gt;&gt;不编译引用已删除的函数</int,>

时间:2014-08-29 17:25:32

标签: visual-c++ c++11 stl

#include <iostream>
#include <memory>
#include <list>
#include <map>
using namespace std;

struct test {
    test(const test&) = delete;
    test& operator = (const test&) = delete;
    test() = default;
    ~test() = default;
};

typedef unique_ptr<test> test_ptr;

int main() {
    list<test_ptr> test_ptr_list;   //This is line 17, where the error occurs
    // comment out next line and it compiles on VC++.
    map<int, list<test_ptr>> test_ptr_map; //error occurs if this is not commented
    return 0;
}

此代码在ideone C++11中编译,但在MSVC++ 2013 CTP Nov 2013中失败。我很确定这应该编译,因为即使我的包装对象无法复制,unique_ptr也可以移动。与list合作正常,而不是map

这是MSVC++错误还是我做错了什么?

错误消息是:

1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xmemory0(600): error C2280: 'std::unique_ptr<test,std::default_delete<_Ty>>::unique_ptr(const std::unique_ptr<_Ty,std::default_delete<_Ty>> &)' : attempting to reference a deleted function
1>          with
1>          [
1>              _Ty=test
1>          ]
1>          c:\program files (x86)\microsoft visual studio 12.0\vc\include\memory(1486) : see declaration of 'std::unique_ptr<test,std::default_delete<_Ty>>::unique_ptr'
1>          with
1>          [
1>              _Ty=test
1>          ]
1>          c:\program files (x86)\microsoft visual studio 12.0\vc\include\xmemory0(723) : see reference to function template instantiation 'void std::allocator<_Other>::construct<_Objty,const std::unique_ptr<test,std::default_delete<_Ty>>&>(_Objty *,const std::unique_ptr<_Ty,std::default_delete<_Ty>> &)' being compiled
1>          with
1>          [
1>              _Other=std::_List_node<std::unique_ptr<test,std::default_delete<test>>,void *>
1>  ,            _Objty=std::unique_ptr<test,std::default_delete<test>>
1>  ,            _Ty=test
1>          ]
1>          c:\program files (x86)\microsoft visual studio 12.0\vc\include\xmemory0(723) : see reference to function template instantiation 'void std::allocator<_Other>::construct<_Objty,const std::unique_ptr<test,std::default_delete<_Ty>>&>(_Objty *,const std::unique_ptr<_Ty,std::default_delete<_Ty>> &)' being compiled
1>          with
1>          [
1>              _Other=std::_List_node<std::unique_ptr<test,std::default_delete<test>>,void *>
1>  ,            _Objty=std::unique_ptr<test,std::default_delete<test>>
1>  ,            _Ty=test
1>          ]
1>          c:\program files (x86)\microsoft visual studio 12.0\vc\include\xmemory0(872) : see reference to function template instantiation 'void std::allocator_traits<_Alloc>::construct<_Ty,const std::unique_ptr<test,std::default_delete<test>>&>(std::allocator<_Other> &,_Objty *,const std::unique_ptr<test,std::default_delete<test>> &)' being compiled
1>          with
1>          [
1>              _Alloc=std::allocator<std::_List_node<std::unique_ptr<test,std::default_delete<test>>,void *>>
1>  ,            _Ty=std::unique_ptr<test,std::default_delete<test>>
1>  ,            _Other=std::_List_node<std::unique_ptr<test,std::default_delete<test>>,void *>
1>  ,            _Objty=std::unique_ptr<test,std::default_delete<test>>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 12.0\vc\include\xmemory0(872) : see reference to function template instantiation 'void std::allocator_traits<_Alloc>::construct<_Ty,const std::unique_ptr<test,std::default_delete<test>>&>(std::allocator<_Other> &,_Objty *,const std::unique_ptr<test,std::default_delete<test>> &)' being compiled
1>          with
1>          [
1>              _Alloc=std::allocator<std::_List_node<std::unique_ptr<test,std::default_delete<test>>,void *>>
1>  ,            _Ty=std::unique_ptr<test,std::default_delete<test>>
1>  ,            _Other=std::_List_node<std::unique_ptr<test,std::default_delete<test>>,void *>
1>  ,            _Objty=std::unique_ptr<test,std::default_delete<test>>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 12.0\vc\include\list(835) : see reference to function template instantiation 'void std::_Wrap_alloc<std::allocator<_Other>>::construct<_Ty,const std::unique_ptr<test,std::default_delete<test>>&>(_Ty *,const std::unique_ptr<test,std::default_delete<test>> &)' being compiled
1>          with
1>          [
1>              _Other=std::_List_node<std::unique_ptr<test,std::default_delete<test>>,void *>
1>  ,            _Ty=std::unique_ptr<test,std::default_delete<test>>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 12.0\vc\include\list(835) : see reference to function template instantiation 'void std::_Wrap_alloc<std::allocator<_Other>>::construct<_Ty,const std::unique_ptr<test,std::default_delete<test>>&>(_Ty *,const std::unique_ptr<test,std::default_delete<test>> &)' being compiled
1>          with
1>          [
1>              _Other=std::_List_node<std::unique_ptr<test,std::default_delete<test>>,void *>
1>  ,            _Ty=std::unique_ptr<test,std::default_delete<test>>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 12.0\vc\include\list(1062) : see reference to function template instantiation 'std::_List_node<std::unique_ptr<test,std::default_delete<_Ty>>,void *> *std::_List_buy<std::unique_ptr<_Ty,std::default_delete<_Ty>>,_Alloc>::_Buynode<const std::unique_ptr<_Ty,std::default_delete<_Ty>>&>(std::_List_node<std::unique_ptr<_Ty,std::default_delete<_Ty>>,void *> *,std::_List_node<std::unique_ptr<_Ty,std::default_delete<_Ty>>,void *> *,const std::unique_ptr<_Ty,std::default_delete<_Ty>> &)' being compiled
1>          with
1>          [
1>              _Ty=test
1>  ,            _Alloc=std::allocator<test_ptr>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 12.0\vc\include\list(1062) : see reference to function template instantiation 'std::_List_node<std::unique_ptr<test,std::default_delete<_Ty>>,void *> *std::_List_buy<std::unique_ptr<_Ty,std::default_delete<_Ty>>,_Alloc>::_Buynode<const std::unique_ptr<_Ty,std::default_delete<_Ty>>&>(std::_List_node<std::unique_ptr<_Ty,std::default_delete<_Ty>>,void *> *,std::_List_node<std::unique_ptr<_Ty,std::default_delete<_Ty>>,void *> *,const std::unique_ptr<_Ty,std::default_delete<_Ty>> &)' being compiled
1>          with
1>          [
1>              _Ty=test
1>  ,            _Alloc=std::allocator<test_ptr>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 12.0\vc\include\list(1424) : see reference to function template instantiation 'void std::list<test_ptr,std::allocator<_Ty>>::_Insert<const std::unique_ptr<test,std::default_delete<test>>&>(std::_List_unchecked_const_iterator<std::_List_val<std::_List_simple_types<_Ty>>,std::_Iterator_base0>,const std::unique_ptr<test,std::default_delete<test>> &)' being compiled
1>          with
1>          [
1>              _Ty=test_ptr
1>          ]
1>          c:\program files (x86)\microsoft visual studio 12.0\vc\include\list(1424) : see reference to function template instantiation 'void std::list<test_ptr,std::allocator<_Ty>>::_Insert<const std::unique_ptr<test,std::default_delete<test>>&>(std::_List_unchecked_const_iterator<std::_List_val<std::_List_simple_types<_Ty>>,std::_Iterator_base0>,const std::unique_ptr<test,std::default_delete<test>> &)' being compiled
1>          with
1>          [
1>              _Ty=test_ptr
1>          ]
1>          c:\program files (x86)\microsoft visual studio 12.0\vc\include\list(1384) : see reference to function template instantiation 'void std::list<test_ptr,std::allocator<_Ty>>::_Insert_range<_Iter>(std::_List_unchecked_const_iterator<std::_List_val<std::_List_simple_types<_Ty>>,std::_Iterator_base0>,_Iter,_Iter,std::forward_iterator_tag)' being compiled
1>          with
1>          [
1>              _Ty=test_ptr
1>  ,            _Iter=std::_List_const_iterator<std::_List_val<std::_List_simple_types<std::unique_ptr<test,std::default_delete<test>>>>>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 12.0\vc\include\list(1384) : see reference to function template instantiation 'void std::list<test_ptr,std::allocator<_Ty>>::_Insert_range<_Iter>(std::_List_unchecked_const_iterator<std::_List_val<std::_List_simple_types<_Ty>>,std::_Iterator_base0>,_Iter,_Iter,std::forward_iterator_tag)' being compiled
1>          with
1>          [
1>              _Ty=test_ptr
1>  ,            _Iter=std::_List_const_iterator<std::_List_val<std::_List_simple_types<std::unique_ptr<test,std::default_delete<test>>>>>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 12.0\vc\include\list(924) : see reference to function template instantiation 'std::_List_iterator<std::_List_val<std::_List_simple_types<std::unique_ptr<test,std::default_delete<_Ty>>>>> std::list<test_ptr,std::allocator<std::unique_ptr<_Ty,std::default_delete<_Ty>>>>::insert<std::_List_const_iterator<std::_List_val<std::_List_simple_types<std::unique_ptr<_Ty,std::default_delete<_Ty>>>>>>(std::_List_const_iterator<std::_List_val<std::_List_simple_types<std::unique_ptr<_Ty,std::default_delete<_Ty>>>>>,_Iter,_Iter)' being compiled
1>          with
1>          [
1>              _Ty=test
1>  ,            _Iter=std::_List_const_iterator<std::_List_val<std::_List_simple_types<std::unique_ptr<test,std::default_delete<test>>>>>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 12.0\vc\include\list(924) : see reference to function template instantiation 'std::_List_iterator<std::_List_val<std::_List_simple_types<std::unique_ptr<test,std::default_delete<_Ty>>>>> std::list<test_ptr,std::allocator<std::unique_ptr<_Ty,std::default_delete<_Ty>>>>::insert<std::_List_const_iterator<std::_List_val<std::_List_simple_types<std::unique_ptr<_Ty,std::default_delete<_Ty>>>>>>(std::_List_const_iterator<std::_List_val<std::_List_simple_types<std::unique_ptr<_Ty,std::default_delete<_Ty>>>>>,_Iter,_Iter)' being compiled
1>          with
1>          [
1>              _Ty=test
1>  ,            _Iter=std::_List_const_iterator<std::_List_val<std::_List_simple_types<std::unique_ptr<test,std::default_delete<test>>>>>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 12.0\vc\include\list(917) : while compiling class template member function 'std::list<test_ptr,std::allocator<_Ty>>::list(const std::list<_Ty,std::allocator<_Ty>> &)'
1>          with
1>          [
1>              _Ty=test_ptr
1>          ]
1>          c:\program files (x86)\microsoft visual studio 12.0\vc\include\xstring(1123) : see reference to function template instantiation 'std::list<test_ptr,std::allocator<_Ty>>::list(const std::list<_Ty,std::allocator<_Ty>> &)' being compiled
1>          with
1>          [
1>              _Ty=test_ptr
1>          ]
1>          c:\code\test\test\main.cpp(17) : see reference to class template instantiation 'std::list<test_ptr,std::allocator<_Ty>>' being compiled
1>          with
1>          [
1>              _Ty=test_ptr
1>          ]
  

PS :使用更简单的方法在CONNECT上发布此内容 std::pair<int, std::vector<std::unique_ptr<int>>> int_pair;

PPS 错误已修复,修复程序将包含在 VS14 RTM 中。

1 个答案:

答案 0 :(得分:0)

MSVC错误已修复,修复程序将包含在VS14 RTM中:https://connect.microsoft.com/VisualStudio/feedbackdetail/view/960021