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

non-conforming allocatable array -- error not caught

vivekrao4
Beginner
369 Views

In the following invalid program

program xalloc
implicit none
integer, allocatable :: ii(:),jj(:)
allocate (ii(2),jj(3))
jj = 0
ii = jj ! invalid -- arrays do not conform
! jj = ii
print*,ii
end program xalloc

IVF 9.1.034 with the options

/traceback /check:all /warn:all /warn:unused

compiles and runs, giving output "0 0" modulo spacing. If the line "jj = ii" is uncommented the program terminates at that line, with an informative error message. It appears that the array bounds checking catches cases where the RHS array is smaller than the LHS array but not where the RHS array is larger. It would be nice to catch the latter. G95 exhibits the same behavior, but Mingw gfortran 4.3.0 20070329 catches both cases. It would be nice if the Intel compiler caught both cases.

I believe that in Fortran 2003, if the LHS is an allocatable array, it need not conform to the RHS, although they must have the same rank. The LHS array is allocated to be the same shape as the RHS. This feature seems convenient but a little dangerous to me.

0 Kudos
1 Reply
Steven_L_Intel1
Employee
369 Views
Correct on both counts. The compiler does not currently do "shape checking" on array assignments. We have actually implemented the F2003 feature you mention but have not enabled it yet as the performance penalty is severe.
0 Kudos
Reply