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
This commit is contained in:
Henry Schreiner
2020-09-10 11:49:26 -04:00
committed by GitHub
parent fbc7563623
commit 621906b3e7
8 changed files with 89 additions and 17 deletions

View File

@@ -175,14 +175,20 @@ TEST_SUBMODULE(copy_move_policies, m) {
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(); });