Skip to content

Commit 218732d

Browse files
henryiiirwgk
authored andcommitted
fix: apply simpler expression with fewer workarounds
1 parent 3d2cb7c commit 218732d

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

include/pybind11/detail/type_caster_base.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -927,20 +927,17 @@ template <typename type> class type_caster_base : public type_caster_generic {
927927
using Constructor = void *(*)(const void *);
928928

929929
/* Only enabled when the types are {copy,move}-constructible *and* when the type
930-
does not have a private operator new implementation. */
930+
does not have a private operator new implementation. A comma operator is used in the decltype
931+
argument to apply SFINAE to the public copy/move constructors.*/
931932
template <typename T, typename = enable_if_t<is_copy_constructible<T>::value>>
932-
static auto make_copy_constructor(const T *x) -> decltype(new T(*x), Constructor{}) {
933-
PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(x);
934-
PYBIND11_WORKAROUND_INCORRECT_OLD_GCC_UNUSED_BUT_SET_PARAMETER(x);
933+
static auto make_copy_constructor(const T *) -> decltype(new T(std::declval<const T>()), Constructor{}) {
935934
return [](const void *arg) -> void * {
936935
return new T(*reinterpret_cast<const T *>(arg));
937936
};
938937
}
939938

940939
template <typename T, typename = enable_if_t<std::is_move_constructible<T>::value>>
941-
static auto make_move_constructor(const T *x) -> decltype(new T(std::move(*const_cast<T *>(x))), Constructor{}) {
942-
PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(x);
943-
PYBIND11_WORKAROUND_INCORRECT_OLD_GCC_UNUSED_BUT_SET_PARAMETER(x);
940+
static auto make_move_constructor(const T *) -> decltype(new T(std::declval<T&&>()), Constructor{}) {
944941
return [](const void *arg) -> void * {
945942
return new T(std::move(*const_cast<T *>(reinterpret_cast<const T *>(arg))));
946943
};

0 commit comments

Comments
 (0)