From 7ae210d5db5eb96989b2f639e65678b5597e61f0 Mon Sep 17 00:00:00 2001 From: Paul Thomas Date: Sat, 5 Dec 2020 14:14:19 +0000 Subject: [PATCH] Fortran: flag formal argument before resolving an array spec [PR98016]. 2020-12-05 Paul Thomas 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 | 4 ++++ gcc/testsuite/gfortran.dg/pr98016.f90 | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/pr98016.f90 diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index b6d21ad1bac..0a8f90775ab 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -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 index 00000000000..71df67e6190 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr98016.f90 @@ -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 +! +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 -- 2.30.2