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

Problem with parameterized derived type declared with ALLOCATABLE attribute

FortranFan
Honored Contributor II
233 Views

The following simple code compiles with no errors or warnings with Intel(R) Visual Fortran Compiler XE 15.0.1.148 but it generates a run-time error with the parameterized derived type that has an ALLOCATABLE attribute.  Is this due to incorrect code or a bug in Intel Fortran?

Thanks,

PROGRAM p

   USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY : I4 => INT32, SP => REAL32, DP => REAL64, QP => REAL128

   IMPLICIT NONE

   TYPE :: t(k,n)
      INTEGER(I4), KIND :: k = SP
      INTEGER(I4), LEN  :: n = 1
      REAL(k)           :: x(n)
   END TYPE t

   !.. Local variables
   TYPE(t) :: boo
   TYPE(t(QP,2)) :: foo
   TYPE(t(DP,:)), ALLOCATABLE :: goo
   INTEGER(I4) :: Istat
   CHARACTER(LEN=80) :: ErrAlloc

   PRINT *, " Test #72: PDT"
   PRINT *

   PRINT *, " boo%n = ", boo%n
   boo%x = REAL(-1.0, KIND=boo%k)
   PRINT *, " boo%x = ", boo%x
   PRINT *

   PRINT *, " foo%n = ", foo%n
   foo%x = REAL(0.0, KIND=foo%k)
   PRINT *, " foo%x = ", foo%x
   PRINT *

   ALLOCATE( t(DP,3) :: goo, STAT=Istat, ERRMSG=ErrAlloc)
   IF (Istat /= 0) THEN
      PRINT *, " Allocation of goo failed: STAT = ", Istat, "; error message = ", ErrAlloc
   END IF
   PRINT *, " goo%n = ", goo%n
   PRINT *, " Shape of goo%x is (", LBOUND(goo%x, DIM=1), ":", UBOUND(goo%x, DIM=1), ")"
   goo%x = REAL(1.0, KIND=goo%k)
   PRINT *, " goo%x = ", goo%x
   PRINT *

   !..
   STOP

END PROGRAM p
  Test #72: PDT

  boo%n =  1
  boo%x =  -1.000000

  foo%n =  2
  foo%x =  0.00000000000000000000000000000000
 0.00000000000000000000000000000000

  goo%n =  3
  Shape of goo%x is ( 1 : 3 )
forrtl: severe (408): fort: (2): Subscript #1 of the array X has value 1 which i
s greater than the upper bound of 0

Image              PC        Routine            Line        Source
TestFor32.exe      01135C94  Unknown               Unknown  Unknown
TestFor32.exe      01133537  _MAIN__                    39  TestFor.f90
TestFor32.exe      011A53E2  Unknown               Unknown  Unknown
TestFor32.exe      011A5DAA  Unknown               Unknown  Unknown
TestFor32.exe      011A5EFD  Unknown               Unknown  Unknown
kernel32.dll       7576338A  Unknown               Unknown  Unknown
ntdll.dll          7735BF32  Unknown               Unknown  Unknown
ntdll.dll          7735BF05  Unknown               Unknown  Unknown
Press any key to continue . . .

 

0 Kudos
2 Replies
Steven_L_Intel1
Employee
233 Views

Same as https://software.intel.com/en-us/forums/topic/536334

0 Kudos
FortranFan
Honored Contributor II
233 Views

Steve Lionel (Intel) wrote:

Same as https://software.intel.com/en-us/forums/topic/536334

Thanks, Steve.  Good to know it is not coding error, I was going crazy for a while there!

0 Kudos
Reply