https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84074
Bug ID: 84074
Summary: Incorrect indexing of array when actual argument is an
array expression and dummy is polymorphic
Product: gcc
Version: 7.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: vladimir.fuka at gmail dot com
Target Milestone: ---
Base on
https://stackoverflow.com/questions/48468922/creating-a-subset-of-an-array-of-derived-type-in-fortran-doesnt-work-what-am-i/48470594#48470594
Problem appears not just for vector subscript expressions, but I also confirmed
for array(2:1:-1).
type :: t
integer :: n
end type
type(t) :: array(2) = [t(1),t(2)]
call sub(array((/1,2/)))
contains
subroutine sub(a)
class(t) :: a(:)
integer :: i
print *, "loop a(i) :"
do i=1,size(a)
print *,a(i)%n
enddo
print *, "a%n :",a%n
print *, "a(1:size(a))%n :",a(1:size(a))%n
end subroutine
end program
Expected output is 1 and 2 for all three.
Actual output:
> gfortran-7 vecsubs2.f90
> ./a.out
loop a(i) :
2
0
a%n : 1 2
a(1:size(a))%n : 1 2