c – 为什么在MSVC12中,is_copy_constructible为unique_ptr返回true

我会预料这个静态断言:
#include <type_traits>
#include <memory>

int main() {
  static_assert(std::is_copy_constructible<std::unique_ptr<int>>::value,"UPtr has copy constructor?");
}

但是没有.

使用MSVC12编译:

Microsoft (R) C/C++ Optimizing Compiler Version 18.00.31101 for x64

解决方法

static_assert应该触发,std::unique_ptr一个隐式删除的副本构造函数,所以这是一个错误.这看起来与这个bug报告 std::is_copy_constructible is broken有关:

(1) std::is_copy_constructible returns true for types with deleted
copy constructors.

(2) std::is_copy_constructible returns true for types that compose
types that are not copy constructible.

答复是:

Thanks for reporting this bug. We’ve fixed it,and the fix will be available in the next major version of Visual Studio after 2013.

另请参阅此错误报告:std::is_copy_constructible doesn’t work correctly.

请注意,使用最新版本的Visual Studiowebcompiler上的断言触发.最后一次更新是在2015年12月3日.断言也在cl(see it live)和gcc上触发.

我发现一个错误报告:A strange behavior of std::is_copy_constructible它与你的代码非常相似:

static_assert(std::is_copy_constructible<std::unique_ptr<int>>::value,"");

答复有:

Thanks for reporting this bug. We’ve already fixed it,and the fix is
available in VS 2015 Preview.

不清楚,这是什么版本的Visual Studio这是固定的.一个回应说,2013年底版本,而后期说2015年预览.

相关文章

本程序的编译和运行环境如下(如果有运行方面的问题欢迎在评...
水了一学期的院选修,万万没想到期末考试还有比较硬核的编程...
补充一下,先前文章末尾给出的下载链接的完整代码含有部分C&...
思路如标题所说采用模N取余法,难点是这个除法过程如何实现。...
本篇博客有更新!!!更新后效果图如下: 文章末尾的完整代码...
刚开始学习模块化程序设计时,估计大家都被形参和实参搞迷糊...