-
Notifications
You must be signed in to change notification settings - Fork 15.5k
Closed
Labels
Description
Trying to read a (non-real) string into a real variable unexpectedly succeeds instead of throwing an error if both
- the string starts with
dore, - 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:
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 reproducerwhich 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:
- Flang should throw a compile-time error as no standard-conform, explicit field width in the format
"(Dw.d)"is provided. This is howgfortranbehaves. - Flang should correctly detect during runtime that the string cannot be transformed into a
realin a meaningful way and provideiostat != 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.