aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gfortran.dg/pr107872.f90
blob: 09838479e920edbe8ac04bd164fa2416c43d469f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
! { dg-do run }
!
! Test the fix for PR107872, where an ICE occurred in
! resolve.cc(derived_inaccessible) because derived types with
! recursive allocatable components were not catered for.
!
module mod1
  type t
     integer :: data
     type(t), allocatable :: next
   contains
     procedure, private :: write_t
     generic :: write(formatted) => write_t
  end type
contains
  recursive subroutine write_t(this, unit, iotype, v_list, iostat, iomsg)
    class(t), intent(in) :: this
    integer, intent(in) :: unit
    character(*), intent(in) :: iotype
    integer, intent(in) :: v_list(:)
    integer, intent(out) :: iostat
    character(*), intent(inout) :: iomsg
    if (ALLOCATED(this%next)) &
         write (unit, '(dt)') this%next
    write (unit, '(i2)') this%data
  end subroutine
end module

  use mod1
  type(t) :: a
  character (8) :: buffer
  a%data = 1
  allocate (a%next)
  a%next%data = 2
  allocate (a%next%next)
  a%next%next%data = 3
  write (buffer, '(dt)')a
  deallocate (a%next)
  if (trim (buffer) .ne. ' 3 2 1') stop 1
end