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

ALLOCATE() works when type-spec is specified for CHARACTER in mixed-type statement

ur
New Contributor II
1,292 Views

 

I believe this program should produce an error and it does not


program testit
implicit none
character(len=:),allocatable :: s(:)
integer,allocatable :: i(:)
real,allocatable :: r(:)
allocate(character(len=20) :: s(10), i(10), r(10))
write(*,*)size(i),size(r),size(s),len(s)
end program testit
(test1) urbanjs@venus:~/github/bugs$ ifort x1.f90
(test1) urbanjs@venus:~/github/bugs$ ./a.out
10 10 10 20

 

If I try something with other mixed types in an ALLOCATE like

allocate(integer :: i(10),r(10))

I get an error like:

! x1.f90(7): error #8235: If type specification appears, the type and kind
! type parameters of each object being allocated must be the same as type
! and kind type parameters of the type specification. [R]

 

 

0 Kudos
1 Solution
Igor_V_Intel
Employee
530 Views

This bug is fixed in the latest Intel Fortran compiler:

$ ifort test.f90

test.f90(3): error #8235: If type specification appears, the type and kind type parameters of each object being allocated must be the same as type and kind type parameters of the type specification.  [I]

allocate( character :: s, i )

--------------------------^

compilation aborted for test.f90 (code 1)


$ ifort -V

Intel(R) Fortran Intel(R) 64 Compiler Classic for applications running on Intel(R) 64, Version 2021.8.0 Build 20221119_000000



View solution in original post

0 Kudos
7 Replies
andrew_4619
Honored Contributor II
1,240 Views

allocate(integer :: size(i), size(r))  does not make sense to me, is that what you intended to write?

 

0 Kudos
ur
New Contributor II
1,232 Views

No.  Something like "allocate(integer ::  i(10), r(10))" where

integer,allocatable :: i(:)

real,allocatable :: r(:)

 

Just noting that other ALLOCATE(3f) statements do produce an error when a type-spec is present, but the one in the example code does not.

 

0 Kudos
Arjen_Markus
Honored Contributor I
1,225 Views

Well, the first allocate you showed (allocate (character(30) :: ... ) allocates two character arrays, the type specification is for the length of the character strings, but each array is of the same basic type. That is not the case with the second one: you specify the type as integer, but the second array is a real array, so a different basic type.

0 Kudos
ur
New Contributor II
1,213 Views

allocate(character(len=20) :: s(10), i(10), r(10))

 

is the line I am saying is non-standard, where S is character, I is integer, R is real, but there is a type-spec. Per the cited statement from the standard and after discussion on other forums that line is non-standard.  If Ifort was providing an extension then I would expect other statements with mixed types to work also, but instead get an error message if the type-spec is INTEGER or REAL; indicating the line with the CHARACTER type-spec is being ignored inadvertently and that this is not an intentional extension.

0 Kudos
FortranFan
Honored Contributor II
1,154 Views

Readers are encouraged to read this thread at Fortran Discourse site.

I do wish OP had gone with a really short illustration of the issue e.g.,

   character(len=:), allocatable :: s
   integer, allocatable :: i
   allocate( character :: s, i )
end

 

Intel team: please note a support request #05231947 has already been submitted with this short case at the Intel OSC.

0 Kudos
Igor_V_Intel
Employee
1,085 Views

It is escalated to the Intel Fortran development team and should be fixed. Note that same behaviour is observed with ifx (LLVM based Fortran compiler).


0 Kudos
Igor_V_Intel
Employee
531 Views

This bug is fixed in the latest Intel Fortran compiler:

$ ifort test.f90

test.f90(3): error #8235: If type specification appears, the type and kind type parameters of each object being allocated must be the same as type and kind type parameters of the type specification.  [I]

allocate( character :: s, i )

--------------------------^

compilation aborted for test.f90 (code 1)


$ ifort -V

Intel(R) Fortran Intel(R) 64 Compiler Classic for applications running on Intel(R) 64, Version 2021.8.0 Build 20221119_000000



0 Kudos
Reply