aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gfortran.dg/dtio_25.f90
blob: 8ca084899de77ecf974a0ad7a88c58b6b4ebbe42 (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
! { dg-do run }
! PR78854 namelist write to internal unit.
module m
  implicit none
  type :: t
    character :: c
    integer :: k
  contains
    procedure :: write_formatted
    generic :: write(formatted) => write_formatted
    procedure :: read_formatted
    generic :: read(formatted) => read_formatted
  end type
contains
  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
    if (iotype.eq."NAMELIST") then
      write (unit, '(a1,a1,i3)') dtv%c,',', dtv%k
    else
      write (unit,*) dtv%c, dtv%k
    end if
  end subroutine
  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
    character :: comma
    if (iotype.eq."NAMELIST") then
      read (unit, '(a1,a1,i3)') dtv%c, comma, dtv%k
    else
      read (unit,*) dtv%c, comma, dtv%k
    end if
    if (comma /= ',') STOP 1
  end subroutine
end module

program p
  use m
  implicit none
  character(len=50) :: buffer
  type(t) :: x
  namelist /nml/ x
  x = t('a', 5)
  write (buffer, nml)
  if (buffer.ne.'&NML  X=a,  5  /') STOP 1
  x = t('x', 0)
  read (buffer, nml)
  if (x%c.ne.'a'.or. x%k.ne.5) STOP 2
end