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. :). So, C8107 forbids module foo implicit none integer i, j namelist /nml1/ i namelist /nml1/ j ! Legal, simply a continuation end module foo program bar use foo ! nml1 available via USE association implicit none integer k namelist /nml1/ k ! Invalid via C8107 end program bar gfortran accepts the above as an extension. This is essentially your testcase. module foo implicit none integer i end module foo program bar use foo, only : k => i implicit none character(len=10) :: str ="&nml1 k=1/" namelist /nml1/k read(str,nml=nml1) if (k /= 1) stop 1 end program bar 'i' is renamed to 'k'; so 'i' is not accessible via USE associate by that name. With my patch, the namelist uses 'k' and its backing storage is that of 'i'. Now, the interesting case is gfortran.dg/namelist_use_only.f90, which I think is invalid but gfortran currently accepts! That code reduces to 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
