Silverfrost Forums

Welcome to our forums

Compiler does not report incorrect invocation of SHAPE()

6 Feb 2024 3:39 #31036

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:

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):

 Shape(ki) =           10
 In SUB, shape(arg) =     56687753

The output from FTN95 (64-bit):

 Shape(ki) =           10
 In SUB, shape(arg) =            1

A compile time warning or error message would be helpful.

7 Feb 2024 7:15 #31041

mecej4

Many thanks for the welcome feedback. I have added this to the log.

7 Feb 2024 8:16 #31042

An error report has been added for the next release of FTN95.

Please login to reply.