Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28988 Discussions

Finalization of variables of extended type

sstamat
Beginner
296 Views

There seems to be a bug in ifort Version 13.0.1.117 regarding the finalization of allocated variables of extended type.
I don't think it has been reported in the forum.

Consider the following code:

[fortran]

MODULE modu
  TYPE :: a_t
   CONTAINS
     FINAL :: d_a
  END TYPE a_t



  TYPE, EXTENDS (a_t) :: b_t
   CONTAINS
     FINAL :: d_b
  END TYPE b_t


CONTAINS
  SUBROUTINE d_a(this)
    TYPE (a_t) :: this
    PRINT *, "finalize a"
  END SUBROUTINE d_a


  SUBROUTINE d_b(this)
    TYPE (b_t) :: this
    PRINT *, "finalize b"
  END SUBROUTINE d_b
END MODULE modu

PROGRAM test
    USE modu


    PRINT *, " sub1 "
    CALL sub1()
    PRINT *, " sub2 "
    CALL sub2()
    PRINT *, " sub3 "
    CALL sub3()

CONTAINS
  SUBROUTINE sub1()
    TYPE (b_t) :: c
  END SUBROUTINE sub1

  SUBROUTINE sub2()
    CLASS (a_t), ALLOCATABLE :: c
    ALLOCATE(b_t :: c)
  END SUBROUTINE sub2


  SUBROUTINE sub3()
    CLASS (a_t), ALLOCATABLE :: c
    ALLOCATE(b_t :: c)
    DEALLOCATE(c)
    PRINT *, "deallocated"
  END SUBROUTINE sub3
END PROGRAM test
[/fortran]

The finalization process for the variables in each of the subroutines sub1, sub2, sub3 is different (although it shouldn't be):
The variable in sub1 is finalized correctly (the final routine for the extended type is called, which, in turn, calls the final routine of the base type).
The variable in sub2 is finalized by calling the final routine of the base type (the declared type) only.
The variable in sub3 is finalized when deallocated explicitly by calling twice (!) the final routine of the base type. It is finalized again (although it shouldn't) at the end of the subroutine, by calling once the final routine of the base type.

0 Kudos
1 Reply
Steven_L_Intel1
Employee
296 Views
Thanks, we'll take a look.
0 Kudos
Reply