Re: [PATCH] [PR118793] Provide expanded diagnostics for namelist read

Harald Anlauf <[email protected]> Wed, 24 Jun 2026 23:09:40 +0200
Newsgroups gmane.comp.gcc.patches,gmane.comp.gcc.fortran
Message-ID <[email protected]>
Hi Jerry,

the patch looks fine.  However, I wonder if it should also
improve the diagnostics for testcase namelist_101.f90.

A slightly extended version does not show the line and column,
but requires the user to count elements:

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', c1 = '1',"
   write(unit,*) "  c1 = '1', c1 = '1',  c2 = 2 ,"
   write(unit,*) "/"
   rewind(unit)
   read (unit ,nml=tovs_obs_chan)
   close(unit ,status="delete")
end program nml_quotes_bug

This gives - with or without your patch:

At line 12 of file namelist_101.f90 (unit = 10, file = 'nml-quotes-bug.nml')
Fortran runtime error: Missing quote while reading item 5

Error termination. Backtrace:
...

Cheers,
Harald

Am 24.06.26 um 3:40 AM schrieb Jerry D:
> The attached patch is fairly self explanatory.
> 
> I added and check on the message length to not exceed 128 bytes to avoid 
> potential problems with excessively long namelist input lines.
> 
> Two existing test cases are updated to match the dg-output expected for 
> those tests. I do not think a new test case is needd.  Even so, with the 
> original test case given in the PR we would give:
> 
> $ $FC pr118793.f90
> $ ./a.out
>   <ERROR>FILE: namelist read: misplaced = sign
>   <ERROR>INTERNAL: namelist read: misplaced = sign
>   <ERROR>SCRATCH: namelist read: misplaced = sign
> STOP 1
> 
> With the change we now give:
> 
> 
> $ $FC pr118793.f90
> $ ./a.out
>   <ERROR>FILE: namelist read: misplaced = sign at line 3, column 12 in 
> file _config.nml
>    param2 === 0.5 ! problematic line
>             ^
> 
>   <ERROR>INTERNAL: namelist read: misplaced = sign at line 3, column 12
>    param2 === 0.5 ! problematic line
>             ^
> 
>   <ERROR>SCRATCH: namelist read: misplaced = sign at line 3, column 12 
> in file /tmp/gfortrantmpU5c3Ib
>    param2 === 0.5 ! problematic line
>             ^
> 
> STOP 1