aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran/match.c
diff options
context:
space:
mode:
authorJerry DeLisle <jvdelisle@gcc.gnu.org>2021-02-19 12:47:54 -0800
committerJerry DeLisle <jvdelisle@gcc.gnu.org>2021-02-19 12:47:54 -0800
commitdfa2f821c18b7e926b5f5d6e394a0c915937db5e (patch)
treedb8df1cf647142fab67bad6b2152187c9e158d1b /gcc/fortran/match.c
parentd1e7e83aaf11274266d83b7be5ce013b95e8b8c2 (diff)
downloadgcc-dfa2f821c18b7e926b5f5d6e394a0c915937db5e.zip
gcc-dfa2f821c18b7e926b5f5d6e394a0c915937db5e.tar.gz
gcc-dfa2f821c18b7e926b5f5d6e394a0c915937db5e.tar.bz2
fortran: Object types should be declared before use in NAMELIST.
gcc/fortran/ChangeLog: PR fortran/98686 * match.c (gfc_match_namelist): If BT_UNKNOWN, check for IMPLICIT NONE and and issue an error, otherwise set the type to its IMPLICIT type so that any subsequent use of objects will will confirm their types. gcc/testsuite/ChangeLog: PR fortran/98686 * gfortran.dg/namelist_4.f90: Modify. * gfortran.dg/namelist_98.f90: New test.
Diffstat (limited to 'gcc/fortran/match.c')
-rw-r--r--gcc/fortran/match.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/gcc/fortran/match.c b/gcc/fortran/match.c
index 2df6191d..4d5890f 100644
--- a/gcc/fortran/match.c
+++ b/gcc/fortran/match.c
@@ -5536,6 +5536,24 @@ gfc_match_namelist (void)
if (m == MATCH_ERROR)
goto error;
+ if (sym->ts.type == BT_UNKNOWN)
+ {
+ if (gfc_current_ns->seen_implicit_none)
+ {
+ /* It is required that members of a namelist be declared
+ before the namelist. We check this by checking if the
+ symbol has a defined type for IMPLICIT NONE. */
+ gfc_error ("Symbol %qs in namelist %qs at %C must be "
+ "declared before the namelist is declared.",
+ sym->name, group_name->name);
+ gfc_error_check ();
+ }
+ else
+ /* If the type is not set already, we set it here to the
+ implicit default type. It is not allowed to set it
+ later to any other type. */
+ gfc_set_default_type (sym, 0, gfc_current_ns);
+ }
if (sym->attr.in_namelist == 0
&& !gfc_add_in_namelist (&sym->attr, sym->name, NULL))
goto error;