1 // { dg-do compile } 2 3 bool f(); 4 5 struct counted_base { destroycounted_base6 virtual void destroy() { } releasecounted_base7 void release() { if (f()) destroy(); } 8 }; 9 10 struct shared_count { shared_countshared_count11 shared_count() { } ~shared_countshared_count12 ~shared_count() { if (pi) pi->release(); } shared_countshared_count13 shared_count(shared_count& r) : pi(r.pi) { if (pi) pi->release(); } 14 counted_base* pi; 15 }; 16 17 struct Foo; 18 19 struct shared_ptr { operator *shared_ptr20 Foo& operator*() { return *ptr; } 21 Foo* ptr; 22 shared_count refcount; 23 }; 24 25 struct Bar { 26 Bar(Foo&, shared_ptr); 27 }; 28 g()29void g() { 30 shared_ptr foo; 31 new Bar(*foo, foo); 32 } 33 34