mirror of
https://github.com/pybind/pybind11.git
synced 2026-04-20 06:49:25 +00:00
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:
@@ -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(); });
|
||||
|
||||
Reference in New Issue
Block a user