为什么在MSVC12中is_copy_constructible对于unique_ptr返回true [英] Why does is_copy_constructible return true for unique_ptr in MSVC12

查看:82
本文介绍了为什么在MSVC12中is_copy_constructible对于unique_ptr返回true的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我会希望触发此静态断言:

I would have expected this static assertion to fire:

#include <type_traits>
#include <memory>

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

但事实并非如此。

使用MSVC12编译:

Compiled using MSVC12:


Microsoft(R)C / C ++优化x64编译器版本18.00.31101

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


推荐答案

static_assert 应该触发, std :: unique_ptr 具有隐式删除的副本构造函数,所以这是一个错误。这看起来与此错误报告 std相关: :is_copy_constructible已损坏

The static_assert should fire, std::unique_ptr has an implicitly deleted copy constructor, so this is a bug. This looks related to this bug report std::is_copy_constructible is broken:


(1)std :: is_copy_constructible对于删除了
复制构造函数的类型返回true

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

(2)std :: is_copy_constructible对于组成不可复制构造的
类型的类型,返回true。

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

,响应为:


感谢报告此错误。我们已经对其进行了修复,该修复程序将在2013年之后的下一个主要Visual Studio版本中提供。

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无法正常工作

Also, see this bug report: std::is_copy_constructible doesn't work correctly.

请注意,断言会在使用以下命令的 webcompiler 上触发日期版本的Visual Studio。最近一次更新是在 2015年12月3日。该断言还会在clang( 实时查看 )和gcc上触发。

Note that the assert fires on webcompiler which is using an up to date version of Visual Studio. The last update was on Dec 3, 2015. The assert also fires on clang(see it live) and gcc.

我发现了一个错误报告: std :: is_copy_constructible 的奇怪行为,其代码与您的代码非常相似:

I found a bug report: A strange behavior of std::is_copy_constructible which has very similar code to yours:

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

响应如下:


感谢您报告此错误。我们已经修复了该问题,该修复程序是VS 2015 Preview中提供的

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

不清楚,哪个版本的Visual Studio已修复此问题。一个响应说是2013年末版本,而后面一个响应是2015年预览。

Not clear, what version of Visual Studio this is fixed in. One response says late 2013 version while the later on says 2015 Preview.

这篇关于为什么在MSVC12中is_copy_constructible对于unique_ptr返回true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆