<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/137776>137776</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[flang] incorrect iostat for failed list-separated read into real
</td>
</tr>
<tr>
<th>Labels</th>
<td>
flang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Inker2401
</td>
</tr>
</table>
<pre>
There appears to be some (possibly) non-standard conforming behaviour concerning the reading of an internal file (string) containing `..` into a real variable. Consider the following program:
```
program flang_read_dots
implicit none
character(len=2) :: str
real :: x
complex :: z
integer :: n, ierr
str='..'
! With status checks
read(str,*,iostat=ierr) x ! ierr=0 (success) and then x is read as 0.0 (non-standard behaviour)
print *, 'Read real number ierr, val =', ierr, x
read(str,*,iostat=ierr) n ! ierr is non-zero as expected as cannot read to integer
print *, 'Read integer number ierr, val =', ierr, n
read(str,*,iostat=ierr) z ! ierr is non-zero as expected as cannot read to complex
print *, 'Read complex number ierr, val=', ierr, z
! Without status checks
read(str,*) x ! read succeeds (incorrectly!)
print *, 'Read real number (no stat check) val =', x
read(str,*) n ! read does not succeed, runtime error raised
print *, 'Read integer number (no stat check) val =', n
read(str,*) z ! read does not succeed, runtime warning
print *, 'Read complex number (no stat check) val =', z
end program flang_read_dots
```
The `str` containing `..` when read into `x` gives `0.0` with `iostat=0` for success (likewise, `iostat` is omitted, no runtime error is raised). This appears to be possibly non-standard conforming behaviour, as various other compilers such as ifort, Cray Fortran and gfortran all raise a runtime error (and will also return non-zero `iostat` codes).
I suspect it has to do with the interpretation decimal point as if `str` is initialised to `hi`, then a non-zero `iostat` value is returned as expected. Similarly, if the `decimal="comma"` argument is passed into the `read` statement, a non-zero value for `iostat` is also returned.
Compiler explorer link: [https://godbolt.org/z/9doTaGqKT](https://godbolt.org/z/9doTaGqKT)
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyclsFu4zgPx59GuRA1HLlO4k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