Ticket #10798: boost-movelib-unique_ptr-deleter-issue.cc

File boost-movelib-unique_ptr-deleter-issue.cc, 789 bytes (added by Matteo Settenvini <matteo.settenvini@…>, 8 years ago)

Small example showing the compilation error

Line 
1#include <boost/move/unique_ptr.hpp>
2#include <boost/interprocess/offset_ptr.hpp>
3#include <boost/intrusive/pointer_traits.hpp>
4
5using boost::interprocess::offset_ptr;
6
7/*
8 * Note: this example does not necessarily need to make
9 * much sense. It is meant only to show the problem,
10 * the reasons why this is needed would be a bit
11 * long to explain, but they have to do with virtuality
12 * being forbidden in shared memory.
13 */
14
15struct B {};
16struct D : public B {};
17
18
19struct Deleter
20{
21 typedef offset_ptr<B> pointer; // e.g. requirement of boost::interprocess::shared_ptr
22 void operator() (offset_ptr<void> p)
23 {
24 // Destroy via custom allocator.
25 }
26};
27
28
29int
30main()
31{
32 boost::movelib::unique_ptr<D, Deleter> ptr (new D);
33 offset_ptr<D> d = ptr.get(); // <- fails to compile
34}
35