fix: support nvcc and test (#2461)
* fix: support nvcc and test
* fixup! fix: support nvcc and test
* docs: mention what compilers fail
* fix: much simpler logic
* refactor: slightly faster / clearer
diff --git a/tests/test_copy_move.cpp b/tests/test_copy_move.cpp
index 0f698bd..34f1c61 100644
--- a/tests/test_copy_move.cpp
+++ b/tests/test_copy_move.cpp
@@ -175,14 +175,20 @@
m.attr("has_optional") = false;
#endif
- // #70 compilation issue if operator new is not public
+ // #70 compilation issue if operator new is not public - simple body added
+ // but not needed on most compilers; MSVC and nvcc don't like a local
+ // struct not having a method defined when declared, since it can not be
+ // added later.
struct PrivateOpNew {
int value = 1;
private:
-#if defined(_MSC_VER)
-# pragma warning(disable: 4822) // warning C4822: local class member function does not have a body
-#endif
- void *operator new(size_t bytes);
+ void *operator new(size_t bytes) {
+ void *ptr = std::malloc(bytes);
+ if (ptr)
+ return ptr;
+ else
+ throw std::bad_alloc{};
+ }
};
py::class_<PrivateOpNew>(m, "PrivateOpNew").def_readonly("value", &PrivateOpNew::value);
m.def("private_op_new_value", []() { return PrivateOpNew(); });