Why is_copy_constructible returns true for unique_ptr in MSVC12

I would expect this static statement to fire:

#include <type_traits>
#include <memory>

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

But this is not so.

Compiled using MSVC12:

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

+11
source share
2 answers

static_assertshould work, std :: unique_ptr has an implicitly deleted copy instance, so this is an error. This looks related to this std :: is_copy_constructible error message not working :

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

(2) std:: is_copy_constructible true , , .

:

. , Visual Studio 2013 .

. : std:: is_copy_constructible .

, assert webcompiler, Visual Studio. Dec 3, 2015. clang ( ) gcc.

: std:: is_copy_constructible, :

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

:

. , VS 2015.

, Visual Studio . 2013 , - 2015 .

+15

:

#include <stdio.h>
#include <type_traits>

class A {
public:
    A(const A&) = delete;
    void operator=(const A&) = delete;
};

class B {
private:
    B(const B&) = delete;
    void operator=(const B&) = delete;
};

class C {
public:
    C(const C&) = delete;
    void operator=(const C&) = delete;
    void operator=(C) = delete;
};

class D {
private:
    D(const D&) = delete;
    void operator=(const D&) = delete;
    void operator=(D) = delete;
};

int main() {
    printf("%d %d\n", std::is_copy_constructible<A>::value, std::is_copy_assignable<A>::value);
    printf("%d %d\n", std::is_copy_constructible<B>::value, std::is_copy_assignable<B>::value);
    printf("%d %d\n", std::is_copy_constructible<C>::value, std::is_copy_assignable<C>::value);
    printf("%d %d\n", std::is_copy_constructible<D>::value, std::is_copy_assignable<D>::value);
}

MSVC2013 x64 (18.00.40629 for x64) :

1 1    //A
0 1    //B
1 0    //C
0 0    //D

.

, , MSVC2013, . , , , ( - ).

P.S. .

0

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


All Articles