msvc is_copy_assignable始终为true吗? [英] msvc is_copy_assignable always true?
问题描述
#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 $ c失败$ c>,而函数
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?
推荐答案
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:
int:正确
A:正确
B:正确
is_copy_assignable:
int: true
A: true
B: true
在 gcc 4.8.1 我得到了:
is_copy_assignable:
int:true
A:true
B:错误
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:
int:true
A:true
B:错误
is_copy_assignable:
int: true
A: true
B: false
您对Beta的感觉如何;)
How do you feel about betas ;)
这篇关于msvc is_copy_assignable始终为true吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!