The test-case below captures the gist of an error; where is the cause that the adjustable array is bigger than what has been passed in. It cannot be caught by the compiler; I understand. I am wondering is there a way (as in a flag) to catch it at run-time. Compiling with ifort /check:all Test.f90 won't do.
As you can imagine this is extracted from rather deep inside a combination of legacy and new program. In one of the test-cases of that program, it revealed itself as "access violation" but that was at a different location.
Integer :: M, N
Integer :: L
M = 3; N = 5
End Subroutine Set
Integer :: K(N) ! Size is larger than what's passed; its incorrect.
Integer :: L
K = -1 ! any way to catch this error at run-time?
L = K(N) - 1 ! or here?
Write(*,"(2(A,X,I0,X))") "in Tech: K(N) =", K(N), " and L =", L
End Subroutine Tech
End Module OM
Integer, Allocatable :: I(:)
I = 0
Write(*,"(A,X,I0,X)") "after the call L =", L
End Program Test
Did you try /check:bounds?
A question: can you not use assumed-shape array argument and if the length is inadequate, do some error handling instead?
subroutine Tech(K) ! Argument list integer :: K(:) !<-- assumed shape .. if ( size(K) < N ) then ! Size is shorter than desired, do the needful ..
Thanks for your comment.
(a) As I mentioned, this doesn't get trapped with /check:all. So, no /check:bounds won't catch it.
(b) Yes, there are ways to rectify this. But since this is coming from some legacy things, I am wondering if it can't be caught.
Intel Fortran doesn't offer a check for this sort of thing. It would require passing extra information in a way that would break existing programs.
Better to use assumed-shape arrays.