http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55603
--- Comment #3 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-12-05 10:14:03 UTC --- (In reply to comment #1) > The problem seems to be that we fail to do auto-deallocation of the function > result (after the assignment). One should check the standard, if and where > this > is actually demanded. Nowhere. It only falls into the category "quality of implementation". But a reasonable place would be after the place where finalization would occur. > Btw, this will also be important for the future FINAL implementation. Yes, after the function has evaluated, its result has to be finalized. I think it should be as following: tmp = bar(); final_wrapper (a); ! must be after "bar()" a = *tmp; final_wrapper (*tmp); free (tmp); With an allocatable LHS it gets messier due to the length type parameter (and shape). In addition, it seems as if one had always to finalize the LHS in an intrinsic assignment while the (re)allocation is only allowed if the shape doesn't match. >From F2008, "4.5.6.3 When finalization occurs": "If an executable construct references a function, the result is finalized after execution of the innermost executable construct containing the reference." "When an intrinsic assignment statement is executed, the variable is finalized after evaluation of expr and before the definition of the variable." By the way, the latter implies that a temporary variable has to be used if there is a finalizer and the RHS doesn't return a pointer/allocatable. Otherwise one had to finalize the LHS before evaluating the RHS expr.