Bug 65347 - [F03] Final subroutine not called for function result
Summary: [F03] Final subroutine not called for function result
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 5.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Keywords: wrong-code
Depends on:
Blocks: Finalization
  Show dependency treegraph
Reported: 2015-03-08 13:31 UTC by eddyg_61-bugzilla
Modified: 2018-09-28 06:27 UTC (History)
1 user (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed: 2015-03-20 00:00:00


Note You need to log in before you can comment on or make changes to this bug.
Description eddyg_61-bugzilla 2015-03-08 13:31:52 UTC
In the following program the final subroutine are not called
module testfin_mod
implicit none

type tfin
   integer :: t = -1
   final :: del_tfin
   final :: del_tfinv
end type


   function Ctfin(s) result(this)
     integer,intent(in) :: s
	 type(tfin) :: this
	 this % t = s
   end function
   subroutine del_tfin(this)
      type(tfin), intent(inout) :: this
      print *,"Finalized", this % t      
   end subroutine
   subroutine del_tfinv(this)
      type(tfin), intent(inout) :: this(:)
      print *,"Finalized vector", this % t      
   end subroutine
   subroutine printsomev(a)
      type(tfin) :: a(:)
      print *,'PRV:', a
   end subroutine
   subroutine printsomes(a)
      type(tfin) :: a
      print *,'PRS:', a%t
   end subroutine
   subroutine pluto
      type(tfin),save :: a(3)

      call printsomev([a(2), a(1), a(3)])
      call printsomev([a(2), Ctfin(10), a(3)])
      call printsomes(Ctfin(11))
   end subroutine
end module

program test1
use testfin_mod
implicit none

   call pluto

end program

The standard (as far as I know) requires the temporary variables corresponding to Ctfin(10) and Ctfin(11) to be finalized after the end of the subroutines printsomev and printsomev.

But no finalization take places.

The compiler ifort 13.0.1 correctly calls the final procedures.
Comment 1 janus 2015-03-20 08:29:28 UTC
Confirmed. See also PR 37336 comment 27. This is case (b).
Comment 2 Jürgen Reuter 2018-09-28 06:27:34 UTC
Also still present in trunk.