MCPcopy Create free account
hub / github.com/pybind/pybind11 / PrivateOpNew

Class PrivateOpNew

tests/test_copy_move.cpp:252–263  ·  view source on GitHub ↗

#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.

Source from the content-addressed store, hash-verified

250 // struct not having a method defined when declared, since it can not be
251 // added later.
252 struct PrivateOpNew {
253 int value = 1;
254
255 private:
256 void *operator new(size_t bytes) {
257 void *ptr = std::malloc(bytes);
258 if (ptr) {
259 return ptr;
260 }
261 throw std::bad_alloc{};
262 }
263 };
264 py::class_<PrivateOpNew>(m, "PrivateOpNew").def_readonly("value", &PrivateOpNew::value);
265 m.def("private_op_new_value", []() { return PrivateOpNew(); });
266 m.def(

Callers 1

TEST_SUBMODULEFunction · 0.85

Calls

no outgoing calls

Tested by 1

TEST_SUBMODULEFunction · 0.68