http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46174
--- Comment #4 from Daniel Kraft <domob at gcc dot gnu.org> 2010-10-26 19:00:34 UTC --- (In reply to comment #3) > Possible implementation scheme: vtab$t contains besides the normal type-bound > procedures and init/size/hash also an two function points: $copy and $free, > which are of the kind: > > void $free (struct *DT) { > ... free derived types > if (DT->$vtab->$extends && DT->$vtab->$extends->$free) > DT->$vtab->$extends->$free (DT) > } > > That is, each effective type cleans up its own allocatable components and > moves > on to the parent. If the parent does not have an allocatable component itself, > the $free pointer directly points to an ancestor which has -- or is NULL if no > such ancestor exists. The $copy version works alike. Note that this is basically what I would suggest to do also for finalization -- in principle, "all" that needs to be extended from your scheme is that $free also has to call the appropriate finalizer in-between the frees. (This recursing on parent type is also exactly as finalization is specified by the standard.) And because there may be multiple FINAL procedures differing in rank and the "correct one" must be called in any case, I fear that we have to create a $free for each rank, too (or play some nasty tricks). But that should be more a mechanical change and bloat the resulting code instead of being hard to implement.