Bug 67471 - [F03] Finalizer not invoked for assignment to array section
Summary: [F03] Finalizer not invoked for assignment to array section
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 6.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks: Finalization
  Show dependency treegraph
 
Reported: 2015-09-07 03:30 UTC by Ian Harvey
Modified: 2016-11-08 14:32 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2015-09-07 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ian Harvey 2015-09-07 03:30:21 UTC
gfortran recent trunk r227512 does not invoke the finalizer for the intrinsic assignment (as required by F2008 4.5.6.3p9) to the array section of `b` in the following example:

module tes_final_mod
  implicit none
  type :: my_final
    integer :: n = 0
  contains
    final :: destroy_rank1_array
  end type my_final
contains
  subroutine destroy_rank1_array(self)
    type(my_final), intent(inout) :: self(:)
    if (size(self) /= 0) then
      print "(A,I0,A,*(I0,:,', '))",  &
          'destroy_rank1_array executed for object of size ',  &
          size(self), &
          ' and component values ',  &
          self%n
    else
      print "(A)",  &
          'destroy_rank1_array executed for object of size 0'
    end if
  end subroutine destroy_rank1_array
end module tes_final_mod

program test_finalizer
  use tes_final_mod
  implicit none
  type(my_final) :: b(4), c(2)
  
  b%n = 2
  c%n = 3
  b(1:2) = c
end program test_finalizer


No output is generated, while expected output is:

destroy_rank1_array executed for object of size 2 and component values 2,2

See also https://software.intel.com/en-us/forums/intel-fortran-compiler-for-linux-and-mac-os-x/topic/591918#comment-1838428
Comment 1 Dominique d'Humieres 2015-09-07 09:09:04 UTC
Confirmed from 4.9 up to trunk (6.0). Added to the list of PRs blocking pr37336 (I let you check that it is not a duplicate).