Quantcast
Channel: Intel® Fortran Compiler for Linux* and macOS*
Viewing all articles
Browse latest Browse all 2583

Final subroutine not invoked

$
0
0

Dear All,

It seems, that intel 16.0.3 (I do not have any more recent version currently) shows non-standard behavior when doing finalization: Given a derived type without a final subroutine, but with an allocatable component with final subroutine, the final subroutine of the allocatable component is not invoked, when a given instance of the derived type is finalized.

The example below demonstrates the issue. The destructor of MyType is never invoked, although the allocatable array, where it is stored, should be finalized, when the instance of MyTypeWrapper is goes out of scope (is deallocated).

Best regards,

Bálint

module testmod
  implicit none

  type :: MyType
    integer :: data = 0
  contains
    final :: destruct
  end type MyType

  type :: MyTypeWrapper
    type(MyType), allocatable :: container(:)
  end type MyTypeWrapper

contains

  subroutine destruct(this)
    type(MyType), intent(inout) :: this

    print *, 'Destroying:', this%data
    this%data = 0

  end subroutine destruct

end module testmod


program testifort
  use testmod

  type(MyTypeWrapper), allocatable :: wrapper

  allocate(wrapper)
  allocate(wrapper%container(1))
  wrapper%container(1)%data = 1
  deallocate(wrapper)
  allocate(wrapper)
  allocate(wrapper%container(1))
  wrapper%container(1)%data = 2
  deallocate(wrapper)
  print *, 'DONE'

end program testifort

 

Thread Topic: 

Bug Report

Viewing all articles
Browse latest Browse all 2583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>