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

No runtime error on double allocation (polymorphic)

$
0
0

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


Viewing all articles
Browse latest Browse all 2583

Trending Articles



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