Title
Reuse of base class subobjects
Status
nad
Section
6.7.4 [basic.life]
Submitter
Bill Wade

Created on 2000-06-28.00:00:00 last changed 287 months ago

Messages

Date: 2001-04-15.00:00:00

Rationale (04/01):

Reallocation of a base class subobject is already disallowed by 6.7.4 [basic.life] paragraph 7.

Date: 2022-11-20.07:54:16

6.7.4 [basic.life] and 11.4.7 [class.dtor] 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).

Suggested resolution: 11.4.7 [class.dtor] should be modified so that explicit destruction of base-class sub-objects be made illegal, or legal only under some restrictive conditions.

History
Date User Action Args
2001-05-20 00:00:00adminsetmessages: + msg519
2001-05-20 00:00:00adminsetstatus: open -> nad
2000-06-28 00:00:00admincreate