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

Jerry D <[email protected]> Thu, 25 Jun 2026 15:46:11 -0700
Newsgroups gmane.comp.gcc.patches,gmane.comp.gcc.fortran
Message-ID <[email protected]>
On 6/25/26 11:31 AM, Harald Anlauf wrote:
> Am 25.06.26 um 1:15 AM schrieb Jerry D:
>> On 6/24/26 2:09 PM, Harald Anlauf wrote:
>>> Hi Jerry,
>>>
>>> the patch looks fine.  However, I wonder if it should also
>>> improve the diagnostics for testcase namelist_101.f90.
>>>
>>
>> I would like to get this one committed so I can start clean and see if i can 
>> find the error path for the case you gave here.
>>
>> Is that OK?
> 
> Sure.  Go ahead.
> 
> Harald
> 
The master branch has been updated by Jerry DeLisle <[email protected]>:

https://gcc.gnu.org/g:523be91d54c05016ee09c2f7ffc74d35f56e48e5

commit r17-1907-g523be91d54c05016ee09c2f7ffc74d35f56e48e5
Author: Jerry DeLisle <[email protected]>
Date:   Tue Jun 23 18:17:27 2026 -0700

I studies this further and the next patch I will factor the expanded message 
code to a helper function. Then call this helper for the other locations where 
there is a namlist error.

Thanks,

Jerry

>>> 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
>>>
>>
>>
>