Please find attached patch for fix PR. The original patch was provided
by Steve Kargl in the initial problem report.
OK to commit to master and backport?
Fortran : Implicitly type parameter causes an invalid errorPR96038
If a paramter to declared and initialised before its type is
declared a bogus error is output at the type declaration
idicating that initialisation is missing.
2020-07-09 Steven G. Kargl <ka...@gcc.gnu.org>
gcc/fortran/
PR fortran/96038
* decl.c (add_init_expr_sym): For a symbol that is a
parameter accept an initialisation if it does not have a
value otherwise output a error and reject.
2020-07-09 Mark Eggleston <markeggles...@gcc.gnu.org>
gcc/testsuite/
PR fortran/96038
* gfortran.dg/pr96038.f90: New test.
--
https://www.codethink.co.uk/privacy.html
>From 7dfee4edf9796304c75785bb56610f3e06211f29 Mon Sep 17 00:00:00 2001
From: Mark Eggleston <markeggles...@gcc.gnu.org>
Date: Mon, 6 Jul 2020 07:14:59 +0100
Subject: [PATCH] Fortran : Implicitly type parameter causes an invalid error
PR96038
If a paramter to declared and initialised before its type is
declared a bogus error is output at the type declaration
idicating that initialisation is missing.
2020-07-09 Steven G. Kargl <ka...@gcc.gnu.org>
gcc/fortran/
PR fortran/96038
* decl.c (add_init_expr_sym): For a symbol that is a
parameter accept an initialisation if it does not have a
value otherwise output a error and reject.
2020-07-09 Mark Eggleston <markeggles...@gcc.gnu.org>
gcc/testsuite/
PR fortran/96038
* gfortran.dg/pr96038.f90: New test.
---
gcc/fortran/decl.c | 15 +++++++++------
gcc/testsuite/gfortran.dg/pr96038.f90 | 8 ++++++++
2 files changed, 17 insertions(+), 6 deletions(-)
create mode 100644 gcc/testsuite/gfortran.dg/pr96038.f90
diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c
index 52c2a624b6e..d854b2a0307 100644
--- a/gcc/fortran/decl.c
+++ b/gcc/fortran/decl.c
@@ -1889,13 +1889,16 @@ add_init_expr_to_sym (const char *name, gfc_expr **initp, locus *var_locus)
/* If this symbol is confirming an implicit parameter type,
then an initialization expression is not allowed. */
- if (attr.flavor == FL_PARAMETER
- && sym->value != NULL
- && *initp != NULL)
+ if (attr.flavor == FL_PARAMETER && sym->value != NULL)
{
- gfc_error ("Initializer not allowed for PARAMETER %qs at %C",
- sym->name);
- return false;
+ if (*initp != NULL)
+ {
+ gfc_error ("Initializer not allowed for PARAMETER %qs at %C",
+ sym->name);
+ return false;
+ }
+ else
+ return true;
}
if (init == NULL)
diff --git a/gcc/testsuite/gfortran.dg/pr96038.f90 b/gcc/testsuite/gfortran.dg/pr96038.f90
new file mode 100644
index 00000000000..f1098f33c1b
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr96038.f90
@@ -0,0 +1,8 @@
+! { dg-do compile }
+
+function ifoo()
+ parameter (n = 50)
+ integer n
+ ifoo = n
+end
+
--
2.11.0