]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: Missing error with IMPLICIT none (external) [PR100972]
authorBernhard Reutner-Fischer <aldot@gcc.gnu.org>
Sun, 31 Oct 2021 16:44:45 +0000 (17:44 +0100)
committerBernhard Reutner-Fischer <aldot@gcc.gnu.org>
Fri, 5 Nov 2021 21:09:48 +0000 (22:09 +0100)
gcc/fortran/ChangeLog:

PR fortran/100972
* decl.c (gfc_match_implicit_none): Fix typo in warning.
* resolve.c (resolve_unknown_f): Reject external procedures
without explicit EXTERNAL attribute whe IMPLICIT none (external)
is in effect.

gcc/testsuite/ChangeLog:

PR fortran/100972
* gfortran.dg/implicit_14.f90: Adjust error.
* gfortran.dg/external_implicit_none_3.f08: New test.

gcc/fortran/decl.c
gcc/fortran/resolve.c
gcc/testsuite/gfortran.dg/external_implicit_none_3.f08 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/implicit_14.f90

index e9e23fe1acb16e9beaa7c512d6022b2b557a3673..ab88ab5e9c18a3b42705d4886e599dbb05e5338a 100644 (file)
@@ -4715,7 +4715,7 @@ gfc_match_implicit_none (void)
   if (c == '(')
     {
       (void) gfc_next_ascii_char ();
-      if (!gfc_notify_std (GFC_STD_F2018, "IMPORT NONE with spec list at %C"))
+      if (!gfc_notify_std (GFC_STD_F2018, "IMPLICIT NONE with spec list at %C"))
        return MATCH_ERROR;
 
       gfc_gobble_whitespace ();
index 21126cba262620e0d3f4a41d860b625c6a02450a..1f4abd087208bc4e5cac4a0857313d087061f044 100644 (file)
@@ -2974,6 +2974,19 @@ resolve_unknown_f (gfc_expr *expr)
       return false;
     }
 
+  /* IMPLICIT NONE (external) procedures require an explicit EXTERNAL attr.  */
+  /* Intrinsics were handled above, only non-intrinsics left here.  */
+  if (sym->attr.flavor == FL_PROCEDURE
+      && sym->attr.implicit_type
+      && sym->ns
+      && sym->ns->has_implicit_none_export)
+    {
+         gfc_error ("Missing explicit declaration with EXTERNAL attribute "
+             "for symbol %qs at %L", sym->name, &sym->declared_at);
+         sym->error = 1;
+         return false;
+    }
+
   /* The reference is to an external name.  */
 
   sym->attr.proc = PROC_EXTERNAL;
diff --git a/gcc/testsuite/gfortran.dg/external_implicit_none_3.f08 b/gcc/testsuite/gfortran.dg/external_implicit_none_3.f08
new file mode 100644 (file)
index 0000000..329deed
--- /dev/null
@@ -0,0 +1,17 @@
+! { dg-do compile }
+! { dg-options "-std=f2018" }
+! Tests fix for PR100972 - Fails to warn about missing EXTERNAL attribute
+! Contributed by Gerhard Steinmetz
+
+program p
+   implicit none (external)
+   real, external :: f
+   real :: a
+   real :: b
+   integer :: i
+   character :: c
+   a = f() ! OK
+   b = g() ! { dg-error "Missing explicit declaration with EXTERNAL attribute" }
+   i = h() ! { dg-error "Missing explicit declaration with EXTERNAL attribute" }
+   c = j() ! { dg-error "Missing explicit declaration with EXTERNAL attribute" }
+end
index 8282c1f1f86c1daa4cc00d1b69d6e4fe40f5ab83..422d913fd4fe7c366720c1f193cc56fff088ce7e 100644 (file)
@@ -4,5 +4,5 @@
 ! Support Fortran 2018's IMPLICIT NONE with spec list
 ! (currently implemented as vendor extension)
 
-implicit none (type) ! { dg-error "Fortran 2018: IMPORT NONE with spec list at \\(1\\)" }
+implicit none (type) ! { dg-error "Fortran 2018: IMPLICIT NONE with spec list at \\(1\\)" }
 end