Is 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");

Compiling this in MSVC 2013 Update 3 quits unexpectedly static_assert, and the function fndoes not compile (as expected). This is contradictory, right?

I abuse is_copy_assignable? Is there any other way to check this condition?

+4
source share
2 answers

You are right, this is a mistake: https://connect.microsoft.com/VisualStudio/feedback/details/819202/std-is-assignable-and-std-is-constructible-give-wrong-value-for-deleted-members

I took cplusplus.com is_copy_assignablecode:

#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;
}

And tested it on Visual Studio 2013 and got:

is_copy_assignable:
int: true
A: true
B: true

gcc 4.8.1 :

is_copy_assignable:
int: true
A: true
B: false

, - Visual Studio 2015 . :

is_copy_assignable:
int: true
A: true
B: false

-;)

+3

, , : , . , (C4522), :

#pragma warning (disable: 4522)
class A
{
    A& operator=(const A&) = delete;
    A& operator=(A) = delete;
};
#pragma warning (default: 4522)

std::is_copy_assignable<A>::value false.

+2

Source: https://habr.com/ru/post/1568745/


All Articles