Fortran: Wrong result in read from internal unit?

Is this the expected behavior?

program test
character(len=256) :: line
integer :: num, error
line = "testing"
num = 5
write(6,*) trim(line),num
read(line,*,iostat=error) num
write(6,*) error, num
end program

When I compile it with pgfortran 17.1-0 or 17.4-0 and run it, I get:

 testing            5
            0           -1

which is OK for the first line, but the second? Why change the name of a variable that should not have been read, and why not signal an error that should have happened?

With gfortran 4.8.4 I get something more reasonable:

 testing           5
        5010           5

an unmodified variable and a non-zero error code.

Hi Ignacio Fdez. Galvan,

Looks like a compiler error to me so I’ve added a problem report (TPR#24702) and sent it to engineering for further investigation.

The problem seems to only occur when the first letter of the string begins with a “t”. With other letters, then the expected error occurs.

% cat test.f90
program test
 character(len=256) :: line
 integer :: num, error
 line = "resting"
 num = 5
 write(6,*) trim(line),num
 read(line,*,iostat=error) num
 write(6,*) error, num
 end program
% pgf90 test.f90 -g ; a.out
 resting            5
          225            5

Thanks for the report,
Mat