http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37336
Tobias Burnus <burnus at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |burnus at gcc dot gnu.org --- Comment #14 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-11-27 20:04:21 UTC --- (In reply to comment #13) > class(child),allocatable :: infant > allocate(infant,source=new_child()) > ... the finalizer is called twice: Once at the end of the main program, and > once through the _copy procedure (which is invoked by the ALLOCATE statement), > I think. Not sure if this is the expected behavior. The invocation through the _copy wrapper is a bug for ALLOCATE. However, it's fine for "a = b" which invoke _copy. I believe _copy should use "intent(inout) dst" instead of "intent(out)" dest – and if needed (e.g. intrinsic assignment), _final should be called directly. Then one can also replace "calloc" and "memset '\0'" by a simple "malloc". (Caveat: One should check that coarray components are properly handled; possibly, _copy also needs a "coarray" argument as _final has.) * * * Current FINAL-wrapper patch (submitted) - it is still preparatory and doesn't call finalization subroutines: http://gcc.gnu.org/ml/fortran/2012-11/msg00086.html See also draft patches at https://userpage.physik.fu-berlin.de/~tburnus/final/ and http://gcc.gnu.org/ml/fortran/2012-11/msg00009.html