Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does is_copy_constructible return true for unique_ptr in MSVC12

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?");
}

But it does not.

Compiled using MSVC12:

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

like image 933
sji Avatar asked Dec 07 '15 14:12

sji


1 Answers

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 returns true for types with deleted copy constructors.

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

and the response was:

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.

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

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.

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

The response there is:

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

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

like image 72
Shafik Yaghmour Avatar answered Oct 01 '22 03:10

Shafik Yaghmour