Consider the following code
MODULE mod
TYPE typ
INTEGER :: i = 1
CONTAINS
PROCEDURE :: mul
FINAL :: destruct
END TYPE typ
CONTAINS
FUNCTION mul(a,m) RESULT (b)
CLASS (typ), INTENT (in) :: a
INTEGER, INTENT (in) :: m
CLASS (typ), ALLOCATABLE :: b
ALLOCATE(b, source=a)
b%i = b%i * m
END FUNCTION mul
SUBROUTINE destruct(a)
TYPE (typ), INTENT (inout) :: a
PRINT *, 'destructor called'
END SUBROUTINE destruct
END MODULE mod
PROGRAM test
USE mod
TYPE(typ) :: a, b
b = a
PRINT *
b = mul(a,5)
PRINT *, b%i
END PROGRAM test
When compiled with ifort (version 12.1.1.256), both assignments in the main program call the final subroutine once (for the left hand side variable). I would expect that the second assignment should call it twice; the extra finalization should be for the allocated function result of 'mul'. Is it a bug in ifort or am I wrong?



