https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123321
--- Comment #13 from van.snyder at sbcglobal dot net <van.snyder at sbcglobal dot net> --- On Sat, 2025-12-27 at 23:18 +0000, kargl at gcc dot gnu.org wrote: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123321 > > --- Comment #11 from Steve Kargl <kargl at gcc dot gnu.org> --- > (In reply to [email protected] from comment #9) > > On Sat, 2025-12-27 at 22:06 +0000, kargl at gcc dot gnu.org wrote: > > > > C8107 (R871) The namelist-group-name shall not be a name > > > > accessed by use association. > > > > > > > > and it appears that it is not handled correctly. > > > > > > > > gfortran.dg/namelist_use_only.f90 is using a namelist-group- > > > > name > > > > from the > > > > module. > > > > > > Need to think about this a bit more. I may be misinterpreting > > > C8107. > > > > > > In the bug I posted, the namelist-group-name is local to the main > > program, not accessed by use association. It's a namelist-group- > > object, > > which 8.9 "Namelist Statement" p5 (F18, and F25 draft) explicitly > > says > > can be accessed by use association, that apparently can't be > > renamed > > and then the local name used in a namelist statement. > > Thanks for the follow up. Every time I look at a namelist bug, > I have to go relearn what a namelist is and how to use it. :). I have taken to using namelist to process command-line arguments. I put the "&nml " in the beginning of a character variable, then read the command-line argument after it. If it contains "=" I append "/" and read with namelist, and if not I do other stuff with it. The standard says character data in namelist has to be quoted, and shells "help" with quoting, so I need to add more quotes. I saw a but report that gfortran allows character data in namelist without quotes. That's harmless and helpful; a feature not a bug. Here's an example: ./Invert_Design -o 7/test 'prefix="7/D-" n_design=7 rotate=f show=t max_poisson=5 coolant_temperature=700 distance_method="M" h_value=0.7' …. > Now, the interesting case is gfortran.dg/namelist_use_only.f90, which > I think is invalid but gfortran currently accepts! That code reduces > to Yes, this one should be prohibited by C8103 (in the F18 standard). I don't see a reason for C8103, so long as every namelist-group-object is accessible where the namelist-stmt appears. > module foo > implicit none > integer i > namelist /nml1/i > end module foo > > program bar > use foo, only : k => i, nml1 > implicit none > character(len=10) :: str ="&nml1 i=1/" > read(str,nml=nml1) > if (k /= 1) stop 1 > end program bar > > Here, 'i' is renamed to 'k' and the namelist 'nml1' is use > associated. > gfortran compiles the above and the binary executes. Note, 'i' is > inaccessible, so the read() statement I believe is invalid due to > > F2023, 8.9 NAMELIST statement > ... > 5 A namelist group object shall either be accessed by use or host > association > or shall have its declared type, kind type parameters of the > declared type, > and rank specified by previous statements in the same scoping > unit or > by the implicit typing rules in effect for the scoping unit. > > With my patch, the above code yields > % gfcx -o z w2.f90 > % ./z > At line 11 of file w2.f90 > Fortran runtime error: Cannot match namelist object name i Other than getting the namelist-group-name by use association, this is what I would expect.
