https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95293
Bug ID: 95293 Summary: Fortran not passing array by reference Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: libfortran Assignee: unassigned at gcc dot gnu.org Reporter: david.sagan at gmail dot com Target Milestone: --- The test program is: program test implicit none type cb_struct real :: cbar = 0 end type type scratch_struct type (cb_struct) :: cc(10) real :: zz(10) = 0 end type type (scratch_struct), target :: s1 ! s1%cc(2)%cbar = 7 call sub2(s1%cc%cbar) print *, 'Sub2 result:', s1%cc(2)%cbar, ' ! Wrong. Should be 10' s1%zz(2) = 7 call sub3(s1%zz) print *, 'Sub3 result:', s1%zz(2) !-------------------------------------- contains subroutine sub2(vec) real, target, intent(inout) :: vec(:) real, pointer :: ptr ptr => vec(1) print *, 'In sub2:', associated(ptr, s1%cc(1)%cbar), vec(2) vec(2) = 23 s1%cc(2)%cbar = 10 end subroutine sub2 subroutine sub3(vec) real, target, intent(inout) :: vec(:) real, pointer :: ptr ptr => vec(1) print *, 'In sub3:', associated(ptr, s1%zz(1)), vec(2) vec(2) = 23 s1%zz(2) = 10 end subroutine sub3 end program Running gives: > gfortran test.f90 > ./a.out In sub2: F 7.00000000 Sub2 result: 23.0000000 ! Wrong. Should be 10 In sub3: T 7.00000000 Sub3 result: 10.0000000 I get the same result on Linux and Mac with gcc 8.3.1 and gcc 9.3.