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

No runtime error on double allocation (polymorphic)

Ferdinand_T_
New Contributor II
249 Views

Hello,

here's an example demosntrating that double allocation of polymorphic variables does not cause a runtime error condition, as expected.

[fortran]

program p
    type derived_type
        integer, dimension(99) :: lost
    end type
 
    type(derived_type), allocatable :: my_static
    class(derived_type), allocatable :: my_polymorphic
 
    ! runtime-check does not catch double allocation!
    allocate(my_polymorphic, source = derived_type(1))
    allocate(my_polymorphic, source = derived_type(1))
 
    ! runtime-check catches all following double allocations:
    ! forrtl: severe (151): allocatable array is already allocated
!    allocate(my_polymorphic)
!    allocate(my_polymorphic)
!
!    allocate(my_static)
!    allocate(my_static)
!
!    allocate(my_static, source = derived_type(1))
!    allocate(my_static, source = derived_type(1))
end program

[/fortran]

With regards,
Ferdinand

0 Kudos
1 Reply
Ferdinand_T_
New Contributor II
249 Views

PS:
Additional checks with valgrind show that, as demonstrated in the example, a memory leak might go unnoticed without a runtime error.

So that kind of error report (besides beeing defined by the standard as far as I know) is very important for debugging. Hence I would like to ask for that error condition to be raised even for polymorphic variables in future versions of ifort? (currently using 14.0.1).

Best Regards,
Ferdinand

0 Kudos
Reply