No runtime error on double allocation (polymorphic)

No runtime error on double allocation (polymorphic)

Hello,

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

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

With regards,
Ferdinand

2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

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

Leave a Comment

Please sign in to add a comment. Not a member? Join today