mecej4
Joined: 31 Oct 2006 Posts: 1897
|
Posted: Tue Feb 06, 2024 4:39 pm Post subject: Compiler does not report incorrect invocation of SHAPE() |
|
|
The SHAPE intrinsic function may not be applied to assumed-size subprogram arguments. The Fortran 2003 Standard says (emphasis added):
13.7.108 SHAPE (SOURCE [, KIND])
9 Description. Returns the shape of an array or a scalar.
10 Class. Inquiry function.
11 Arguments.
SOURCE may be of any type. It may be a scalar or an array. It shall not be an
unallocated allocatable or a pointer that is not associated. It shall not be an
12 assumed-size array.
Here is a test program where this requirement is not met, and the compiler does not report an error or warning:
Code: | program shapebug
implicit none
integer i,ki(10)
ki = [(i+4, i=1,10)]
print *,'Shape(ki) = ',shape(ki)
call sub(ki)
CONTAINS
subroutine sub(ij)
implicit none
integer ij(*)
print *,'In SUB, shape(arg) = ',shape(ij)
return
end subroutine sub
end program |
The output from FTN95 (32-bit):
Code: | Shape(ki) = 10
In SUB, shape(arg) = 56687753 |
The output from FTN95 (64-bit):
Code: | Shape(ki) = 10
In SUB, shape(arg) = 1 |
A compile time warning or error message would be helpful. |
|