Fortran: flag formal argument before resolving an array spec [PR98016].
authorPaul Thomas <pault@gcc.gnu.org>
Sat, 5 Dec 2020 14:14:19 +0000 (14:14 +0000)
committerPaul Thomas <pault@gcc.gnu.org>
Sat, 5 Dec 2020 14:14:19 +0000 (14:14 +0000)
2020-12-05  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
PR fortran/98016
* resolve.c (resolve_symbol): Set formal_arg_flag before
resolving an array spec and restore value afterwards.

gcc/testsuite/
PR fortran/98016
* gfortran.dg/pr98016.f90: New test.

gcc/fortran/resolve.c
gcc/testsuite/gfortran.dg/pr98016.f90 [new file with mode: 0644]

index b6d21ad1baceb073ba0e5006bf60d0217cba24f6..0a8f90775ab66b3cab62b422bedab69650dc5c18 100644 (file)
@@ -15394,8 +15394,12 @@ resolve_symbol (gfc_symbol *sym)
   else if (mp_flag && sym->attr.flavor == FL_PROCEDURE && sym->attr.function)
     {
       bool saved_specification_expr = specification_expr;
+      bool saved_formal_arg_flag = formal_arg_flag;
+
       specification_expr = true;
+      formal_arg_flag = true;
       gfc_resolve_array_spec (sym->result->as, false);
+      formal_arg_flag = saved_formal_arg_flag;
       specification_expr = saved_specification_expr;
     }
 
diff --git a/gcc/testsuite/gfortran.dg/pr98016.f90 b/gcc/testsuite/gfortran.dg/pr98016.f90
new file mode 100644 (file)
index 0000000..71df67e
--- /dev/null
@@ -0,0 +1,19 @@
+! { dg-do compile }
+!
+! Fix for PR98016 - Used to fail with Error: Variable ā€˜nā€™ cannot appear in the
+! expression at (1) for line 16. Workaround was to declare y to be real.
+!
+! Posted by Juergen Reuter  <juergen.reuter@desy.de>
+!
+program is_it_valid
+  dimension y(3)
+  n=3
+  y=func(1.0)
+  print *, y
+  stop
+contains
+  function func(x) result (y)
+    dimension y(n)
+    y=x
+  end function
+end