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

Finalization of allocatable components

IanH
Honored Contributor III
735 Views

Allocatable components are not being finalized when their parent object is deallocated?

[fortran]

MODULE m
  IMPLICIT NONE
 
  TYPE :: Thing
  CONTAINS
    FINAL :: thing_Final
  END TYPE Thing
 
  TYPE, PUBLIC :: Parent
    TYPE(Thing), ALLOCATABLE :: a_thing
  CONTAINS
    FINAL :: parent_Final
  END TYPE Parent
CONTAINS
  SUBROUTINE thing_Final(obj)
    TYPE(Thing), INTENT(INOUT) :: obj
    PRINT *, 'Component final'
  END SUBROUTINE thing_Final
 
  SUBROUTINE parent_Final(obj)
    TYPE(Parent), INTENT(INOUT) :: obj
    PRINT *, 'Parent final'
  END SUBROUTINE parent_Final
END MODULE m

PROGRAM final_test
  USE m
  IMPLICIT NONE
  TYPE(Parent), ALLOCATABLE :: a
  ALLOCATE(a)
  ALLOCATE(a%a_thing)
  DEALLOCATE(a)
END PROGRAM final_test

[/fortran]

[plain]
>ifort /check:all /warn:all /standard-semantics "2013-01-29 final.f90" && "2013-01-29 final.exe"
Intel(R) Visual Fortran Compiler XE for applications running on IA-32, Version 13.0.1.119 Build 20121008
Copyright (C) 1985-2012 Intel Corporation.  All rights reserved.

2013-01-29 final.f90(20): remark #7712: This variable has not been used.   [OBJ]
  SUBROUTINE parent_Final(obj)
--------------------------^
2013-01-29 final.f90(15): remark #7712: This variable has not been used.   [OBJ]
  SUBROUTINE thing_Final(obj)
-------------------------^
Microsoft (R) Incremental Linker Version 10.00.40219.01
Copyright (C) Microsoft Corporation.  All rights reserved.

"-out:2013-01-29 final.exe"
-subsystem:console
"2013-01-29 final.obj"
 Parent final[/plain]

In the above the parent object is finalizable, but I think even if it wasn't (no final:: parent_Final statement) the finalizer for a%a_thing should still be called.  Mentioned previously in http://software.intel.com/en-us/forums/topic/278463 and http://software.intel.com/en-us/forums/topic/284434 and possibly in other threads, so perhaps this is all well known, but I couldn't find a definitive issue id.

0 Kudos
4 Replies
IanH
Honored Contributor III
735 Views

Odd... I think Mr Forum Software is playing silly games.  I see a "The breadcrumb insertion has been deleted." message in the header and the post doesn't show up in the forum post list.  Perhaps I'm talking to myself.  Oh well, in that case "How's the family?"  "They're fine, thanks.", etc.

Edit to note that the post appeared in the list perhaps almost a day later?

0 Kudos
Steven_L_Intel1
Employee
735 Views

I've seen that "breadcrumb" message - it can be ignored.  The developers are looking at that.

I will look into your question here.I recall having a discussion with one of the developers on this topic just recently, so it may be a bug being worked on already.

0 Kudos
Steven_L_Intel1
Employee
735 Views

This one astonishes me - it seems so clear from the standard to me.  I have escalated it as issue DPD200240676. I looked at the other threads and they may be related - I'll look at those closer.

0 Kudos
Steven_L_Intel1
Employee
735 Views

I expect this problem to be fixed in Update 5 (late June).

[Edit - we renumbered the updates, so this fix is now planned for Update 5 - same timeframe.]

0 Kudos
Reply