Silverfrost Forums

Welcome to our forums

BUG in FTN95 V5.50

9 Apr 2010 5:54 #6279

FTN95 does not allow allocatable dummy arguments (TR15581 extension to F95). That is as it stands, and the compiler correctly prints a message when given code that uses this extension.

However, if an allocatable array is a member of a structure, it can be inadvertently sneaked in as an argument by passing the structure as the argument, as in this example:

program buggy

type :: squirrel
  integer, dimension(:), allocatable :: iv
end type squirrel

type(squirrel) :: sivec

integer :: i,n

write(*,*)allocated(sivec%iv)  ! should print FALSE or F

n=4
call allocivec(sivec,n)

write(*,*)allocated(sivec%iv)  ! should print TRUE or T

if(allocated(sivec%iv))deallocate(sivec%iv)

contains

subroutine allocivec(sivec,n)
type(squirrel) :: sivec
integer :: n

allocate(sivec%iv(n))

return
end subroutine allocivec

end program buggy

FTN95 happily compiles and the program prints T for both write statements. The correct results are T \n F.

If the 'allocate' statement in the subroutine is commented out, the correct printout would be F \n F, but FTN95 says T \n T still, but seg-faults on the DEALLOCATE statement

This is a contrived example, to be sure. The bug occurred in a larger program of around 31,000 lines, and was quite hard to locate!

12 Apr 2010 8:59 #6281

It is my understanding that FORTRAN 95 doesn't allow ALLOCATABLE components of user defined types - you have to simulate it by using the POINTER attribute for components that you want to ALLOCATE. In which case, the real bug is that FTN95 doesn't spot the illegal syntax?

Please login to reply.