Boost logo

Boost :

From: Ross Smith (ross.s_at_[hidden])
Date: 2001-05-29 23:58:40


John Max Skaller wrote:
>
> Ross Smith wrote:
>
> > That would have helped, yes, but it wasn't the main problem. Consider a
> > slightly elaborated version of the above:
> >
> > struct Y;
> > struct X {
> > Y* y;
> > ~X() { delete y; } // ***
> > };
> > struct Y {
> > X* x;
> > ~Y() { delete x; }
> > };
> >
> > That won't work, of course; the compiler rejects the line marked ***.
>
> Yes. But these are hand coded classes, and you can ..
>
> > It will work if you put the body of ~X() out of line.
>
> But that solution is NOT available for templates.

Huh? X isn't a template. I don't see your point.

> The problem isn't smart pointers per se, the problem
> is template instantiation.

In that case I must have completely missed your point. I thought you
were complaining about not being able to instantiate a smart pointer on
an incomplete type. If you were, I don't think that's a reasonable thing
to expect to be able to do. If you weren't, then I honestly have
absolutely no idea what problem you're talking about. Could you explain
further please? (Preferably with concrete examples; fragments with
uncertain context don't seem to be getting us anywhere.)

> > > But the example is a special case: just consider:
> > >
> > > template<class T1, class T2>
> > > struct X {
> > > smart_ptr<X<T2,T1> > ptr;
> > > };
> > >
> > > to see that it isn't always possible to forward declare things.
> >
> > What's the problem there?
>
> The problem is that there is NO ordering
> of template instances for which lookup in 'expanded'
> classes can work:
>
> struct X<A,B> { smart_ptr<X<B,A> > ptr; };
>
> Woops! We cannot lookup X<B,A>, it isn't
> instantiated till after. With GCC, if smart_ptr
> contains
>
> p->incr()
>
> g++ tries to lookup 'incr' .. and it can't find
> struct X<B,A> to lookup into. What should happen
> is that both 'struct X<A,B>' and 'struct X<B,A>'
> are layed down first, and THEN, if necessary,
> method bodies layed out. g++ incorrectly
> expands inline method bodies too early.

Could you please give an example of an actual complete program (not
fragment) that you claim should work but doesn't?

-- 
Ross Smith <ross.s_at_[hidden]> The Internet Group, Auckland, New Zealand
========================================================================
        "Hungarian notation is the tactical nuclear weapon of
         source code obfuscation techniques." -- Roedy Green

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk