https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64986
--- Comment #12 from Mikael Morin <mikael at gcc dot gnu.org> --- (In reply to Dominique d'Humieres from comment #6) > The test has been introduced at revision r220482, That revision adds interesting comments: > /* For a function with a class array result, save the result as > a temporary, set the info fields needed by the scalarizer and > call the finalization function of the temporary. Note that the > nullification of allocatable components needed by the result > is done in gfc_trans_assignment_1. */ and in gfc_trans_assignment_1, there is: > /* Nullify the allocatable components corresponding to those of the lhs > derived type, so that the finalization of the function result does not > affect the lhs of the assignment. Prepend is used to ensure that the > nullification occurs before the call to the finalizer. So, if finalization for derived types with allocatable components means freeing the allocatable components, the above is more or less a justification for the patch in comment #9. What I don't understand is why there is need for two functions gfc_conv_procedure_call and gfc_trans_assignment_1 doing half of the job, and why deallocation of components, deallocation of whole allocatable and finalization are not handled all at once in a single place.