Hi Harald and Thomas, Thank you for your contributions to understanding the interpretation by different vendors of the F2018 requirements for finalization. While it does appear to be rather chaotic, the differences are down to a small number of "features" of each compiler. Before describing my interpretation of the behaviour of the offerings from other vendors, I should remark briefly about where I am with gfortran. I now have a patch that handles derived types correctly according to F2018 7.5.6.2 and 7.5.6.3, modulo the ambiguous requirement for the handling of parent components that I will come to when discussing ifort. I have a patch ready to fix this, should Intel's interpretation be correct. I have not moved on to class finalization yet because there are memory leaks connected with finalization of function results that I have yet to pin down. Also, finalization of function results within array and structure constructors is yet to come. Once I have it all working, I will break up the patch into a number of stages to make it more digestible for review. However, just in case I fall under the proverbial bus, I have attached the patch for reference. Turning to the results from the other vendors: Cray: Seemingly, the only difference in interpretation concerns the finalization of structure constructors. 7.5.6.3 paragraphs 5 and 6 only mention function results. Having scoured the standard for guidance, I have only found Note 7.57: "name(...) ...snip... is interpreted as a structure constructor only if it cannot be interpreted as a generic function reference." From this, I take it that a structure constructor is distinct from a function reference and, since not mentioned in 7.5.6.3, the result should not be finalized. nagfor 7.1: The NAG offering seems to be a bit inconsistent in the finalization of function results. It is missing in assignment 4 and suffers a surfeit in assignment 5. The two extras in assignment 5 seem to be mangled. As far as I can tell, these are problems of implementation rather than interpretation. ifort: In all the versions tested, assignment 1 generates, contrary to the standard, a finalization of an unallocated allocated 'var'. The other difference from gfortran with the patch applied is in the finalization of the parent component in the finalization of arrays of extended types. ifort makes use of the scalar finalizer, whereas all the other compilers use the array finalizer. In fairness to the folk at Intel, I think that there is an ambiguity in 7.5.6.2 - "(2) All finalizable components that appear in the type definition are finalized in a processor-dependent order. If the entity being finalized is an array, each finalizable component of each element of that entity is finalized separately. (3) If the entity is of extended type and the parent type is finalizable, the parent component is finalized." The separate mention of the parent component in (3) rather than in (2) saying, "..each finalizable component, including the parent component,..." implies that it is in some way different. I think that an interpretation request is in order. I will be unavailable to do any gfortran work for two weeks now but will complete this work then. Best regards and thanks again. Paul On Thu, 17 Feb 2022 at 21:23, Thomas Koenig wrote: > Hi Paul, > > > I have gone back to the start and have gone through finalizable derived > > type assignments with the F2018 in hand. I have had a dreadful time with > > direct by reference function calls and still am struggling with > assignment > > number 6 in the attached. I would be very grateful if you would run this > > testcase for the other brands. > > This is the output of nagfor 7.1, no idea how correct this is. > > Best regards > > Thomas > > At start of program: final_count = 0 > ******************************************************************* > > 1st assignment: No finalization because MyType unallocated. > After 1st assignment(var not allocated): final_count = 0(0) > ******************************************************************* > > 2nd assignment: MyType(=simple(1,MyType) finalized before assignment > finalize simple - Mytype2%ind = 1 > After 2nd assignment(var allocated): final_count = 1(1) > ******************************************************************* > > 3rd assignment: MyTypeArray(%ind = [41 42]) finalized before assignment > > finalize simple(:) - MyTypeArray%ind= 42 43 > After 3rd assignment(array var allocated): final_count = 1(1) > ******************************************************************* > > Deallocation generates final call with self = simple (21, ThyType) > 4th assignment: MyTypeArray finalized before assignment > Mtype finalized before assignment with self = simple (11, MyType) > Function result finalized after assignment with self = simple (99, > MyType) > > finalize simple - ThyType%ind = 21 > finalize simple - MyType%ind = 11 > After 4th assignment(array var allocated) :final_count = 2(3) > ******************************************************************* > > 5th assignment: MyTypeArray finalized before assignment > 1] First finalization is of 'res' in constructor3 with: > Self = [complicated (-1, constructor3, 0.0), complicated (-1, > ThyTypeArra1, 0.0)] > 2] ThyTypeArray is finalized before assignment and after evaluation of > constructor3 > Self = [3 times complicated (-1, ThyTypeArra1,0.0)] > 3] Function result finalized after assignment with > Self = [complicated (-1, ThyTypeArra2, 0.0), complicated (-1, > ThyTypeArra2, 0.0)] > > constructor3: final_count = 0 > finalize complicated(2) - constructor3 = 0 0 0.00 0.00 > finalize simple(:) - constructor3%ind= 0 0 > finalize complicated(3) - ThyTypeArra1 = -1 -1 -1 0.00 0.00 0.00 > finalize simple(:) - ThyTypeArra1%ind= -1 -1 -1 > finalize complicated(2) - ThyTypeArra2 = 1 3 2.00 4.00 > finalize simple(:) - ThyTypeArra2%ind= 1 3 > finalize complicated(2) - IypeArra2 = **** 3 2.00 4.00 > finalize simple(:) - IypeArra2%ind= **** 3 > finalize complicated(2) - IypeArra2 = **** 3 2.00 4.00 > finalize simple(:) - IypeArra2%ind= **** 3 > After 5th assignment(array var allocated): 10(6) > > ******************************************************************* > Deallocate ThyTypeArray. > finalize complicated(2) - ThyTypeArra2 = 1 3 2.00 4.00 > finalize simple(:) - ThyTypeArra2%ind= 1 3 > > ******************************************************************* > 6th assignment: A repeat of the previous with an allocatable function > result. > This should give the same result as the 5th assignment. > > constructor4: final_count = 0 > finalize complicated(2) - constructor4 = 1 1 1.00 1.00 > finalize simple(:) - constructor4%ind= 1 1 > finalize complicated(2) - ThyTypeArra2 = 1 3 2.00 4.00 > finalize simple(:) - ThyTypeArra2%ind= 1 3 > finalize complicated(3) - ThyTypeArra1 = -1 -1 -1 0.00 0.00 0.00 > finalize simple(:) - ThyTypeArra1%ind= -1 -1 -1 > After 6th assignment(array var allocated): 6(6) > > ******************************************************************* > Deallocations at end > > finalize simple - MyType%ind = 99 > After 1st deallocation: 1 > finalize simple - ThyType2%ind = 22 > After 2nd deallocation: 2 > finalize simple(:) - ThyType%ind= 21 22 > After 3rd deallocation: 3 > -- "If you can't explain it simply, you don't understand it well enough" - Albert Einstein