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

            Bug ID: 80333
           Summary: Namelist dtio write of array of class does not
                    traverse the array
           Product: gcc
           Version: 7.0.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jvdelisle at gcc dot gnu.org
  Target Milestone: ---

The following test case shows the wrong behavior. I am pretty sure this is
frontend related. Notice that derived types work OK, but class does not.  This
is because the array specification for an array of class is stored differently
and needs to be  pulled out in trans_io.c (transfer_namelist_element). I have
found the array spec in the component structure, but am not certain how to
handle it.

module m
  implicit none
  type :: t
    character :: c
  contains
    procedure :: read_formatted
    generic :: read(formatted) => read_formatted
    procedure :: write_formatted
    generic :: write(formatted) => write_formatted
  end type t
contains
  subroutine read_formatted(dtv, unit, iotype, v_list, iostat, iomsg)
    class(t), intent(inout) :: dtv
    integer, intent(in) :: unit
    character(*), intent(in) :: iotype
    integer, intent(in) :: v_list(:)
    integer, intent(out) :: iostat
    character(*), intent(inout) :: iomsg
    read(unit,'(a1)', iostat=iostat, iomsg=iomsg) dtv%c
  end subroutine read_formatted

  subroutine write_formatted(dtv, unit, iotype, v_list, iostat, iomsg)
    class(t), intent(in) :: dtv
    integer, intent(in) :: unit
    character(*), intent(in) :: iotype
    integer, intent(in) :: v_list(:)
    integer, intent(out) :: iostat
    character(*), intent(inout) :: iomsg
    write(unit,'(a1)', iostat=iostat, iomsg=iomsg) dtv%c
  end subroutine write_formatted
end module m

program p
  use m
  implicit none
  class(t), dimension(:), allocatable :: w
  type(t), dimension(:), allocatable :: x
  namelist /nml/  w, x
  integer :: unit, iostatus

  allocate(w(10), x(10))
  w = t('j')
  w(5:7)%c='k'
  x = t('p')
  x(4:8)%c='s'
  print *, w
  print *, x
  write(*, nml)
end program p

$ ./a.out 
 j j j j k k k j j j
 p p p s s s s s p p
&NML
 W=j
 X=pppssssspp
 /

Reply via email to