https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98686

--- Comment #4 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> ---
One of this difficulties here is:

"If a namelist group object is typed by the implicit typing rules, its
appearance in any subsequent type declaration statement shall confirm the
implied type and type parameters."

If one takes away the IMPLICIT NONE in the example given, it would be valid
only if the subsequent explicit declarations agreed with the IMPLICIT.  As far
as I know, there is no checking that explicit declarations confirm IMPLICIT.

My thinking is to add the check I have so far and defer the confirmatory checks
elsewhere, maybe as a warning. Otherwise I think it is can of worms.  I do
think it might be useful to warn people about not confirming an implicit type
since it is conceivable that someone might contradict themselves while
modifying legacy codes.  This is why we always recommend IMPLICIT NONE
regardless.

The patch at this point regressions tests OK.

diff --git a/gcc/fortran/match.c b/gcc/fortran/match.c
index 2df6191d7e6..2e6d1db515a 100644
--- a/gcc/fortran/match.c
+++ b/gcc/fortran/match.c
@@ -5536,6 +5536,17 @@ gfc_match_namelist (void)
          if (m == MATCH_ERROR)
            goto error;

+         /* 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.  */
+         if (gfc_current_ns->seen_implicit_none &&
+             sym->ts.type == BT_UNKNOWN)
+           {
+             gfc_error ("Symbol %qs in namelist %qs at %C must be "
+                        "declared before the namelist is declared.",
+                        sym->name, group_name->name);
+             goto error;
+           }
          if (sym->attr.in_namelist == 0
              && !gfc_add_in_namelist (&sym->attr, sym->name, NULL))
            goto error;

Reply via email to