Topic: Defect Report: Lifetime of base class objects


Author: "Bill Wade" <bill.wade@stoner.com>
Date: 2000/06/28
Raw View
[ forwarded to C++ committee.  -sdc ]

3.8 [basic.life] and 12.4 discuss explicit management of object lifetime.
It seems clear that most object lifetime issues apply to sub-objects (array
elements, and data members) as well.  The standard supports

     struct X { T t } x;
     T* pt = &x.t;
     pt->~T();
     new(pt) T;

and this kind of behavior is useful  in allocators.

However the standard does not seem to prohibit the same operations on base
sub-objects.

   struct D: B{ ... } d;
   B* pb = &d;
   pb->~B();
   new(pb) B;

however if B and/or D have virtual member functions or virtual bases, it is
unlikely that this code will result in a well-formed D object in current
implementations (note that the various lines may be in different functions).

I suggest that 12.4 be modified so that explicit destruction of base-class
sub-objects be made illegal, or legal only under some restrictive
conditions.




[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]