[Bug fortran/88169] Rejects USE rename of namelist group

kargl at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Sat Nov 24 19:03:00 GMT 2018


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88169

--- Comment #7 from kargl at gcc dot gnu.org ---
(In reply to kargl from comment #6)
> (In reply to Neil Carlson from comment #5)
> > Stated a bit more clearly, the question is, whether in
> > 
> >   The namelist-group-name shall not be a name accessed by use association.
> > 
> > the name (in the scope of the declaration) is accessed by use association,
> > or the name is accessed in another scope by use association.
> 
> I've asked on the J3 mailing list for clairfication.  14.2.2
> say ", identifiers, and namelist groups in a module."  Namelist 
> groups is a bit vague, here.  Does this mean namelist group names 
> or namelist group objects.  My current thinking is C8102 is to
> prevent
> 
>   module foo
>     ....
>     namelist /bar/ ...
>   end module
> 
>   program bah
>     use foo
>     real x
>     namelist /bar/x
>     ...
>   end program bah
> 
> where program bar is trying to extend the namelist-group-object-list.

So, I've asked on J3 mailing list (and after a rather condescending reply),
it is definitely a bug in gfortran.  Constraint c8102 from F2018 applies
to a namelist-group-name in the scoping unit that USEs the module.  Thus,
in the above code, using 'bar' in program 'bah' as a namelist-group-name is
invalid as 'bar' has been made available via USE association.

This patch allows a slightly modify version of Neil's code to compile and
run (x in main is implicitly defined local variable, which is different 
than the x in module foo).

Index: module.c
===================================================================
--- module.c    (revision 266386)
+++ module.c    (working copy)
@@ -3711,7 +3711,6 @@ static void
 mio_namelist (gfc_symbol *sym)
 {
   gfc_namelist *n, *m;
-  const char *check_name;

   mio_lparen ();

@@ -3722,17 +3721,6 @@ mio_namelist (gfc_symbol *sym)
     }
   else
     {
-      /* This departure from the standard is flagged as an error.
-        It does, in fact, work correctly. TODO: Allow it
-        conditionally?  */
-      if (sym->attr.flavor == FL_NAMELIST)
-       {
-         check_name = find_use_name (sym->name, false);
-         if (check_name && strcmp (check_name, sym->name) != 0)
-           gfc_error ("Namelist %s cannot be renamed by USE "
-                      "association to %s", sym->name, check_name);
-       }
-
       m = NULL;
       while (peek_atom () != ATOM_RPAREN)
        {


% cat a.f90
module foo_nml
   implicit none
   real :: x
   namelist /foo/ x
end module

program main
   use foo_nml, only: bar => foo, x
   implicit none
   x = 42
   write(*,nml=bar)
end program

% gfcx -o z a.f90 && ./z
&FOO
 X=  42.0000000    ,
 /


More information about the Gcc-bugs mailing list