The program below produces the correct result for the first read and nothing
for the second.  ifort and g95 produce the same result for each.  It is my
belief that this construct is not strictly standard compliant but it is widely
used - I found this during my efforts to make iso_varying_string work.

The code looks OK, so I think that the logic in the library needs a little bit
of tweaking:

  nchars = 80;
  {
    struct __st_parameter_dt dt_parm.8;

    dt_parm.8.common.filename = "advance_io.f90";
    dt_parm.8.common.line = 21;
    dt_parm.8.common.unit = 10;
    dt_parm.8.advance = "no";
    dt_parm.8.advance_len = 2;
    dt_parm.8.format = "(a)";
    dt_parm.8.format_len = 3;
    dt_parm.8.size = &nchars;
    dt_parm.8.common.flags = 13328;
    _gfortran_st_read (&dt_parm.8);
    _gfortran_transfer_character (&dt_parm.8, &buffer, NON_LVALUE_EXPR
<nchars>) ;
    _gfortran_st_read_done (&dt_parm.8);
    switch (dt_parm.8.common.flags & 3)
      {
        case 3:;
        goto __label_000999;
      }
  }

Paul

  character(80) :: buffer, line
  integer :: nchars
  line = "The quick brown fox jumps over the lazy dog."
  open (10)
  write (10, '(a)') trim(line)
  rewind (10)
  nchars = 80
  read (10, '(a)', advance = 'no', size = nchars, eor = 998) buffer
998 print *, nchars, buffer
  rewind (10)
  buffer = ""
  nchars = 80
  read (10, '(a)', advance = 'no', size = nchars, eor = 999) buffer (:nchars)
999 print *, nchars, buffer
  close (10)
end


-- 
           Summary: SIZE parameter interacts with same variable in IO list
                    character length specification.
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libfortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: pault at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26890

Reply via email to