https://gcc.gnu.org/g:3e77ce5bcc4d9e467f119bbece5c26cdb4e24210
commit r16-6685-g3e77ce5bcc4d9e467f119bbece5c26cdb4e24210 Author: Jerry DeLisle <[email protected]> Date: Wed Jan 7 21:48:49 2026 -0800 Fortran: [PR123012] Silent acceptance of unquoted character items PR libfortran/123012 libgfortran/ChangeLog: * io/list_read.c (read_character): Add new check when no quate is provided and the character string is digits only. gcc/testsuite/ChangeLog: * gfortran.dg/namelist_100.f90: New test. Diff: --- gcc/testsuite/gfortran.dg/namelist_100.f90 | 16 ++++++++++++++++ libgfortran/io/list_read.c | 6 ++++++ 2 files changed, 22 insertions(+) diff --git a/gcc/testsuite/gfortran.dg/namelist_100.f90 b/gcc/testsuite/gfortran.dg/namelist_100.f90 new file mode 100644 index 000000000000..483cf9fae83d --- /dev/null +++ b/gcc/testsuite/gfortran.dg/namelist_100.f90 @@ -0,0 +1,16 @@ +! { dg-do run ) +! { dg-shouldfail "Missing quote" } +program nml_quotes_bug + implicit none + integer :: unit = 10 + character(8) :: c1, c2 + namelist /tovs_obs_chan/ c1, c2 + open (unit ,file="nml-quotes-bug.nml") + write(unit,*) "&tovs_obs_chan" + write(unit,*) " c1 = '1'," + write(unit,*) " c2 = 2 ," + write(unit,*) "/" + rewind(unit) + read (unit ,nml=tovs_obs_chan) + close(unit ,status="delete") +end program nml_quotes_bug diff --git a/libgfortran/io/list_read.c b/libgfortran/io/list_read.c index ccce4e44a4f3..2aadc8f4d3c1 100644 --- a/libgfortran/io/list_read.c +++ b/libgfortran/io/list_read.c @@ -1314,6 +1314,12 @@ read_character (st_parameter_dt *dtp, int length __attribute__ ((unused))) CASE_SEPARATORS: case EOF: + if (dtp->u.p.namelist_mode) + { + snprintf (message, IOMSG_LEN, "Missing quote while reading item %d", + dtp->u.p.item_count); + generate_error (&dtp->common, LIBERROR_READ_VALUE, message); + } unget_char (dtp, c); goto done; /* String was only digits! */
