https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93256
Bug ID: 93256
Summary: Assumed-shape unlimited polymorphic variable passes
values incorrectly
Product: gcc
Version: 9.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: jman012345 at gmail dot com
Target Milestone: ---
If an unlimited polymorphic variable (using class(*)) of assumed shape is
passed, element by element, from one subroutine to another, the values are
passed in the wrong order. Here's an example:
program test
implicit none
real, dimension(3) :: a
a = [10., 20., 30.]
call sub1([a(1),a(2),a(3)])
contains
subroutine sub1(var)
class(*), dimension(:) :: var
integer :: i
do i=1,size(var)
call sub2(var(i))
end do
end subroutine
subroutine sub2(var)
class(*) :: var
select type (var)
type is (real)
print *,var
end select
end subroutine
end program
The output of this program is
20.0000000
30.0000000
10.0000000
However, if line 5 is changed to "call sub1(a)" then the output is
10.0000000
20.0000000
30.0000000
Also, if sub1 is changed to:
subroutine sub1(var)
class(*), dimension(:) :: var
integer :: i
do i=1,size(var)
select type (var)
type is (real)
call sub2(var(i))
end select
end do
end subroutine
then output is the expected 10, 20, 30 formatted as above.