Silverfrost Forums

Welcome to our forums

Compiler gives false bounds error with /check

2 Feb 2015 12:48 (Edited: 15 Jun 2015 10:46) #15568

In the following program, a section of an assumed shape 2-D array is passed to a function which expects a 1-D array. The 7.10 FTN95 compiler gives a false bounds error as indicated in the listing. Viewing the run in SDBG shows the array X as having a dimension (1) at the point where the program aborted.

The program should run without error.

! Compile with /check and run
! Will give false 'array subscript out of bounds' 
! error in function SNRM2 below
program arraybug
implicit none
real, dimension(:,:), allocatable :: c
integer m,n,i,j
real :: x

m=3
n=4
allocate(c(m,n))
do i=1,m
   do j=1,n
      c(i,j)=100*i+j
   end do
end do
call sub(c,m)

contains
subroutine sub(c,m)
implicit none
integer :: m
real, dimension(:,:) :: c
x=snrm2(m,c(:,2))
write(*,*)x
end subroutine

function snrm2(n,x) result(ssq)
implicit none
real :: x(*),ssq,absxi
integer :: n,i

ssq=0
do i = 1, n
   absxi = abs ( x(i) )   ! <<<=== falsely gives subscript error here!
   ssq = ssq +  absxi**2
end do
return
end function snrm2

end program

[P.S., 15 June 2015: The fix described by Paul Laidler is present in FTN95-7.20]

2 Feb 2015 9:14 #15572

Thanks for this. I have logged it for investigation.

5 Feb 2015 7:55 #15603

For the time being this bug has been 'fixed' by removing the array bounds check for star-sized arguments in internal functions.

Please login to reply.