Closed liuzqt closed 3 years ago
ShmemAllocator::pointer is not a raw pointer and placement new requires something convertible to void*. This is not a bug, the standard allows non-raw pointers in allocators and does not guarantee "new (shm_ptr) int(3)" will compile.
As you've done, you can use (&shm_ptr) to make sure a raw pointer is returned (shm_ptr returns a reference so &shm_ptr is a raw pointer, convertible to void).
I'm using Boost.Interprocess shared memory, and I'm implementing my own container, expecting to work with both stl allocator and boost ipc allocator. When it comes to placement new, the code won't compile.
below is the code to reproduce this
got the compiler error
as shown above, neither the
placement new
orallocator_traits
can work, but the&*
magic did the trick(my colleage told me this, I don't know why...)I'm running boost 1.58, not sure if it's fixed in newer version.