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

            Bug ID: 78854
           Summary: [F03] DTIO namelist output not working on internal
                    unit
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: janus at gcc dot gnu.org
  Target Milestone: ---

Found when working on PR78661:


MODULE m
  IMPLICIT NONE
  TYPE :: t
    CHARACTER :: c
  CONTAINS
    PROCEDURE :: write_formatted
    GENERIC :: WRITE(FORMATTED) => write_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
    WRITE (unit, "(A)", IOSTAT=iostat, IOMSG=iomsg) dtv%c
  END SUBROUTINE
END MODULE

PROGRAM p
  USE m
  IMPLICIT NONE
  character(len=4), dimension(3) :: buffer
  TYPE(t) :: x
  NAMELIST /nml/ x
  x = t('a')
  WRITE (buffer, nml)
  print *, buffer
END



This test case prints:

a
 &NML     / 

It seems that DTIO namelist output does not work on internal units (i.e. when
writing to a string): The second line is the output of the buffer, which is
missing the 'a'. The latter appears in a separate line. Apparently it is
written to std output instead of the buffer?!?

Reply via email to