Le 04/11/2026 à 19:48, Steve Kargl a écrit :
On 11/4/26 02:16, Mikael Morin wrote:
Le 04/11/2026 à 07:44, Steve Kargl a écrit :
I'll let you and Harald decide how to proceed as I have not
been too active in gfortran development lately. However, I
think 6.1.6 is clear. A utf-8 BOM shall not appear as the first
character in a line.
This case is borderline, as the BOM doesn't really represent a
character of the input source. It's more encoding metadata. For the
same reason, I think it should removed from the buffer returned by
load_line.
I have checked, and to my surprise there is a unicode character
corresponding to the BOM. It's "zero width no-break space". So it
should be in the buffer from load_line after all. And it's not among
the "other, control" category of unicode; one might interpret it at
meaning it's not a "control character" of fortran, but that's debatable
I guess.
It's good that we gracefully accept it, but maybe a warning could be
emitted, as we don't check that the characters seen in the source are
consistent with the BOM (that is they are a valid UTF-8 code sequence
if a BOM was seen).
It is an invalid character in the input stream of Fortran tokens.
We have -Wtabs to deal with tabs that are used instead of spaces
(and I still think an error should be the default).
Compile this, run the executable, and then compile foo.f90.
program foo
implicit none
character, parameter :: vt = char(11), nl = char(10), ht = char(9)
character(len=512) buf
integer fd
open(newunit=fd, file='foo.f90', status='replace', access='stream')
buf = ht // vt // 'program foo' // nl
buf = trim(buf) // "print *, 'hello'" // nl
buf = trim(buf) // 'end program ' // vt//ht // 'foo' // nl
write(fd) trim(buf)
close(fd)
end program foo
If you use 'gfortran -o z -Wtabs foo.f90' only the first occurrence
of a horizontal tab is caught. All occurrences of a vertical tab
are flagged as errors. It would seem to me that a BOM is in the
same class as a vertical tab.
Note that we silently accept line feeds, despite them not being
explicitly allowed. ;-)
I tend to agree with you, but I'm afraid some tools may generate BOMs
without users having any control on it.