From ce7024fdf54372508ae9647d8c2547945de357e1 Mon Sep 17 00:00:00 2001 From: Dean Moldovan Date: Tue, 13 Jun 2017 23:47:43 +0200 Subject: [PATCH] Fix linker issue with move constructors on MSVC Fixes the issue as described in the comments of commit e27ea47. This just adds `enable_if_t::value>` to `make_move_constructor`. The change fixes MSVC and is harmless with other compilers. --- include/pybind11/cast.h | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 64d6d530..78fb13c9 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -774,13 +774,23 @@ public: operator itype&() { if (!value) throw reference_cast_error(); return *((itype *) value); } protected: - typedef void *(*Constructor)(const void *stream); + using Constructor = void *(*)(const void *); + /* Only enabled when the types are {copy,move}-constructible *and* when the type - does not have a private operator new implementaton. */ - template ::value>> static auto make_copy_constructor(const T *value) -> decltype(new T(*value), Constructor(nullptr)) { - return [](const void *arg) -> void * { return new T(*((const T *) arg)); }; } - template static auto make_move_constructor(const T *value) -> decltype(new T(std::move(*((T *) value))), Constructor(nullptr)) { - return [](const void *arg) -> void * { return (void *) new T(std::move(*const_cast(reinterpret_cast(arg)))); }; } + does not have a private operator new implementation. */ + template ::value>> + static auto make_copy_constructor(const T *x) -> decltype(new T(*x), Constructor{}) { + return [](const void *arg) -> void * { + return new T(*reinterpret_cast(arg)); + }; + } + + template ::value>> + static auto make_move_constructor(const T *x) -> decltype(new T(std::move(*(T *) x)), Constructor{}) { + return [](const void *arg) -> void * { + return new T(std::move(*const_cast(reinterpret_cast(arg)))); + }; + } static Constructor make_copy_constructor(...) { return nullptr; } static Constructor make_move_constructor(...) { return nullptr; }