<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/151465>151465</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [Flang] reads d* prefixed strings as floating-point values
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            flang
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          marikurz-amd
      </td>
    </tr>
</table>

<pre>
    Trying to read a (non-real) string into a `real` variable unexpectedly succeeds instead of throwing an error if both
- the string starts with `d` or `e`,
- _and_ a floating-point format identifier without explicit width is used.

This behavior can be reproduced with 
```
Flang Version: 21.0.0git commit 532facc78e
```
and the following snippet:
```fortran
program reproducer
implicit none
character(len=4)  :: str = "dstr"
real :: test
integer           :: istat
read(str,"(D)", iostat=istat) test
WRITE(*,*) "Is the string real? ", (istat .EQ. 0)
end program reproducer
```
which yields
```
Is the string real? T
```
Thus, flang compiles and succeeds in reading the string `"dstr"` into a `real` variable, which should not be allowed. If an explicit width is used, such as `"(D4.0)"`, Flang throws `istat != 0` as expected.

In my opinion, the expected behavior would be one of the following:
1. Flang should throw a compile-time error as no standard-conform, explicit field width in the format `"(Dw.d)"` is provided. This is how `gfortran` behaves.
2. Flang should correctly detect during runtime that the string cannot be transformed into a `real` in a meaningful way and provide `iostat != 0`. This is the behavior of Classic-Flang and the Cray compiler.

I would speculate this behavior is somehow caused by `d` and `e` are valid components of a floating-point number in exponential format.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJx8Vc1u8zgSfBr60rBAUf6RDz5o489AjrsIdo8fKLJlcYciBZKy43n6QVNybGSCCQLYAPunuquqLWM0F4d4ZNt_se1pJafU-3AcZDB_TOHPtRz0qvX6fvwId-MukDwElBokMFE779YBpWXiADEFejcueXrc8fyw43CVwcjWIkwOP0dUCbW9Q5yUQtQRjIuJCvoOUh_8jYpIBxiCD2A6aH3qGW_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