]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR fortran/30878 (Rejects function f1; namelist /nml/ f1)
authorPaul Thomas <pault@gcc.gnu.org>
Fri, 11 May 2007 11:42:56 +0000 (11:42 +0000)
committerPaul Thomas <pault@gcc.gnu.org>
Fri, 11 May 2007 11:42:56 +0000 (11:42 +0000)
2007-05-11 Paul Thomas <pault@gcc.gnu.org>

PR fortran/30878
* resolve.c (resolve_fl_namelist): It is not an error if the
namelist element is the result variable of the enclosing
function.  Search for the symbol in current and all parent
namespaces for a potential conflict.
* symbol.c (check_conflict): Remove the conflict between
'in_namelist' and 'FL_PROCEDURE' because the symbol info
is not available to exclude function result variables.
* trans-io.c (nml_get_addr_expr): Use the fake result decl
if the symbol is an implicit result variable.

2007-05-11 Paul Thomas <pault@gcc.gnu.org>

PR fortran/30878
* gfortran.dg/namelist_29.f90: New test.

From-SVN: r124615

gcc/fortran/ChangeLog
gcc/fortran/resolve.c
gcc/fortran/symbol.c
gcc/fortran/trans-io.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/namelist_29.f90 [new file with mode: 0644]

index 342864b39a348125a24ef32dd80e87b8aec6365d..01eb9108e9565f7bde93efb2ffd473b90620fe6a 100644 (file)
@@ -1,3 +1,16 @@
+2007-05-11 Paul Thomas <pault@gcc.gnu.org>
+
+       PR fortran/30878
+       * resolve.c (resolve_fl_namelist): It is not an error if the
+       namelist element is the result variable of the enclosing
+       function.  Search for the symbol in current and all parent
+       namespaces for a potential conflict.
+       * symbol.c (check_conflict): Remove the conflict between
+       'in_namelist' and 'FL_PROCEDURE' because the symbol info
+       is not available to exclude function result variables.
+       * trans-io.c (nml_get_addr_expr): Use the fake result decl
+       if the symbol is an implicit result variable.
+
 2007-05-11  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/31474
index 5c5d40bf6d5c60be8b42d765650862c0b413d7f4..dbb36d37b3595589219900311ad9b2cd0890a175 100644 (file)
@@ -6070,16 +6070,21 @@ resolve_fl_namelist (gfc_symbol *sym)
     }
 
   /* 14.1.2 A module or internal procedure represent local entities
-     of the same type as a namelist member and so are not allowed.
-     Note that this is sometimes caught by check_conflict so the
-     same message has been used.  */
+     of the same type as a namelist member and so are not allowed.  */
   for (nl = sym->namelist; nl; nl = nl->next)
     {
       if (nl->sym->ts.kind != 0 && nl->sym->attr.flavor == FL_VARIABLE)
        continue;
+
+      if (nl->sym->attr.function && nl->sym == nl->sym->result)
+       if ((nl->sym == sym->ns->proc_name)
+              ||
+           (sym->ns->parent && nl->sym == sym->ns->parent->proc_name))
+         continue;
+
       nlsym = NULL;
-      if (sym->ns->parent && nl->sym && nl->sym->name)
-       gfc_find_symbol (nl->sym->name, sym->ns->parent, 0, &nlsym);
+      if (nl->sym && nl->sym->name)
+       gfc_find_symbol (nl->sym->name, sym->ns, 1, &nlsym);
       if (nlsym && nlsym->attr.flavor == FL_PROCEDURE)
        {
          gfc_error ("PROCEDURE attribute conflicts with NAMELIST "
index 0388e54e9f74e1e4e3b569c240a521142002b625..2fef9d52d0b476063b69b322786fe05a9511aab5 100644 (file)
@@ -477,6 +477,7 @@ check_conflict (symbol_attribute * attr, const char * name, locus * where)
 
   if (attr->in_namelist
       && attr->flavor != FL_VARIABLE
+      && attr->flavor != FL_PROCEDURE
       && attr->flavor != FL_UNKNOWN)
     {
 
index 4b87bcba24113ec42f83eda5a20c414a2eeaf43a..e543f4c7c3c0aaee0a19cc1b732cd4818d5fc00f 100644 (file)
@@ -1297,6 +1297,13 @@ nml_get_addr_expr (gfc_symbol * sym, gfc_component * c,
     {
       sym->attr.referenced = 1;
       decl = gfc_get_symbol_decl (sym);
+
+      /* If this is the enclosing function declaration, use
+        the fake result instead.  */
+      if (decl == current_function_decl)
+       decl = gfc_get_fake_result_decl (sym, 0);
+      else if (decl == DECL_CONTEXT (current_function_decl))
+       decl =  gfc_get_fake_result_decl (sym, 1);
     }
   else
     decl = c->backend_decl;
index 641c0508f20c2e3c7d6e6e90d088db3044394f06..0ca48c0db4e25772a7b10924a065568502f037ad 100644 (file)
@@ -1,3 +1,8 @@
+2007-05-11 Paul Thomas <pault@gcc.gnu.org>
+
+       PR fortran/30878
+       * gfortran.dg/namelist_29.f90: New test.
+
 2007-05-11  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/31474
diff --git a/gcc/testsuite/gfortran.dg/namelist_29.f90 b/gcc/testsuite/gfortran.dg/namelist_29.f90
new file mode 100644 (file)
index 0000000..55bff0c
--- /dev/null
@@ -0,0 +1,20 @@
+! { dg-do run }
+! Checks the fix for PR30878, in which the inclusion
+! of an implicit function result variable in a namelist
+! would cause an error.
+!
+! Contributed by Joost VandeVondele <jv244@cam.ac.uk>
+!
+  character(80) :: buffer
+  if (f1 (buffer) .ne. 42) call abort ()
+CONTAINS
+   INTEGER FUNCTION F1 (buffer)
+     NAMELIST /mynml/ F1
+     integer :: check
+     character(80) :: buffer
+     F1 = 42
+     write (buffer, nml = mynml)
+     F1 = 0
+     READ (buffer, nml = mynml)
+   end function
+END