------- Additional Comments From SWElef at post dot sk 2004-12-17 11:12 ------- AFAICT the code in comment #5 is well-formed.
std:12.4/5: An implicitly-declared destructor is implicitly defined when it is used to destroy an object of its class type... Thus, the declaration+definition of class ObjectList only declares ObjectList::~ObjectList() and the implementation is not permitted to define it yet, which also means that the implementation is not permitted to instantiate ListT<Object>::~ListT(). The definition of class Object again only declares Object::~Object(). The first place where a destructor is used is the body of the function "test" where Object::~Object() must be implicitly defined. It forces the implicit definition of ObjectList::~ObjectList() and finaly the instantiation of ListT<Object>::~ListT(). At this point, however, the class Object is already defined so there is no undefined behaviour. (See also std:14.7.1/9 which forbids early instantiation of non-virtual member functions including the discussed dtor.) Note that during the instantiation of ListT<Object>::~ListT() the expression "delete array;" involves a call to _inline_ Object::~Object() that has not been defined yet (it is just waiting to be defined after its member's dtor's implicit definition is completed). I can imagine that this may cause some problems for the implementation but it does not affect the validity of the code. (Note in 7.1.2/4: a call to the inline function may be encountered before its definition appears in the translation unit.) Regards, Vladimir Marko -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17648