https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115781

            Bug ID: 115781
           Summary: Error with passing array of derived type
           Product: gcc
           Version: 14.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: only_for_nouse at gmx dot de
  Target Milestone: ---

Allocating an array of derived type on the top level with bounds other than 1
and then passing it to a subroutine, does correctly change the bounds to start
with 1 but access to the elements of the passed array is wrong.

Building the following code with
gfortran --version
GNU Fortran (GCC) 14.1.0
leads to an output of
top level: mats, lbound=  2, ubound=  4
top level, 2: nRows=  2
top level, 3: nRows=  3
top level, 4: nRows=  4
 in use_mats:  mats, lbound=  1, ubound=  3
    use_mats, 1: nRows=  0
    use_mats, 2: nRows=  2
    use_mats, 3: nRows=  3

while it should show in the use_mats level also the values 2,3,4.



program simple
   implicit none

   type :: matrix
      integer :: nRows
   end type matrix

   class(matrix),dimension(:), allocatable :: mats
   integer :: i

   allocate(mats(2:4))
   do i=lbound(mats,1),ubound(mats,1)
      mats(i)%nRows=i
   end do

   write(*,"(2(A,I3))") "top level: mats, lbound=",lbound(mats),",
ubound=",ubound(mats)
   do i=lbound(mats,1),ubound(mats,1)
      write(*,"(A,I2,A,I3)") "top level, ",i,": nRows=",mats(i)%nRows
   end do
   call use_mats(mats)

contains
   subroutine use_mats(mats)
      class(matrix),dimension(:),intent(IN) :: mats

      integer :: i

      write(*,"(2(A,I3))") " in use_mats:  mats, lbound=",lbound(mats),",
ubound=",ubound(mats)
      do i=lbound(mats,1),ubound(mats,1)
         write(*,"(A,I2,A,I3)") "    use_mats, ",i,": nRows=",mats(i)%nRows
      end do
   end subroutine use_mats

end program simple

Reply via email to