msvc is_copy_assignable always true?(msvc is_copy_assignable 始终为真?)
问题描述
#include <type_traits>
class Test
{
public:
Test(const Test &) = delete;
Test &operator=(const Test &) = delete;
};
void fn(Test &a, const Test &b) { a = b; }
static_assert(!std::is_copy_assignable<Test>::value, "Test shouldn't be assignable");
在 MSVC 2013 Update 3 下编译它意外地使 static_assert
失败,并且函数 fn
无法编译(如预期).这是矛盾的,对吧?
Compiling this under MSVC 2013 Update 3 unexpectedly fails the static_assert
, and the function fn
fails to compile (as expected.) This is contradictory, right?
我是否滥用了is_copy_assignable
?有没有其他方法可以测试这种情况?
Am I misusing is_copy_assignable
? Is there another way to test for this condition?
推荐答案
您说得对,这是一个错误:https://connect.microsoft.com/VisualStudio/feedback/details/819202/std-is-assignable-and-std-is-constructible-give-wrong-value-for-deleted-members
You are correct this is a bug: https://connect.microsoft.com/VisualStudio/feedback/details/819202/std-is-assignable-and-std-is-constructible-give-wrong-value-for-deleted-members
我拿了 cplusplus.com 的 is_copy_assignable
代码:
I took cplusplus.com's is_copy_assignable
code:
#include <iostream>
#include <type_traits>
struct A { };
struct B { B& operator= (const B&) = delete; };
int main() {
std::cout << std::boolalpha;
std::cout << "is_copy_assignable:" << std::endl;
std::cout << "int: " << std::is_copy_assignable<int>::value << std::endl;
std::cout << "A: " << std::is_copy_assignable<A>::value << std::endl;
std::cout << "B: " << std::is_copy_assignable<B>::value << std::endl;
return 0;
}
并在 Visual Studio 2013 上对其进行测试并得到:
And tested it on Visual Studio 2013 and got:
is_copy_assignable:
整数:真
答:是的
乙:真的
is_copy_assignable:
int: true
A: true
B: true
在 gcc 4.8.1 上,我得到了:
is_copy_assignable:
整数:真
答:是的
乙:假
is_copy_assignable:
int: true
A: true
B: false
特别是在 Visual Studio 2015 Beta 上,此问题已修复.我得到:
Notably on the Visual Studio 2015 Beta this is fixed. I get:
is_copy_assignable:
整数:真
答:是的
乙:假
is_copy_assignable:
int: true
A: true
B: false
你对测试版的感觉如何;)
How do you feel about betas ;)
这篇关于msvc is_copy_assignable 始终为真?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:msvc is_copy_assignable 始终为真?


基础教程推荐
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 从 std::cin 读取密码 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01