aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorBernhard Reutner-Fischer <aldot@gcc.gnu.org>2021-10-31 17:44:45 +0100
committerBernhard Reutner-Fischer <aldot@gcc.gnu.org>2021-11-05 22:09:48 +0100
commit1727bb533ede295a3ef2dd494225d27b6d1746aa (patch)
tree08756267680b9488af9104576c2d3c327adc8a34 /gcc
parentc64ca0e7bbe193b95f50b0d3daf9ff7b710d6c6b (diff)
downloadgcc-1727bb533ede295a3ef2dd494225d27b6d1746aa.zip
gcc-1727bb533ede295a3ef2dd494225d27b6d1746aa.tar.gz
gcc-1727bb533ede295a3ef2dd494225d27b6d1746aa.tar.bz2
Fortran: Missing error with IMPLICIT none (external) [PR100972]
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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/fortran/decl.c2
-rw-r--r--gcc/fortran/resolve.c13
-rw-r--r--gcc/testsuite/gfortran.dg/external_implicit_none_3.f0817
-rw-r--r--gcc/testsuite/gfortran.dg/implicit_14.f902
4 files changed, 32 insertions, 2 deletions
diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c
index e9e23fe..ab88ab5 100644
--- a/gcc/fortran/decl.c
+++ b/gcc/fortran/decl.c
@@ -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 ();
diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index 21126cb..1f4abd0 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -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
index 0000000..329deed
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/external_implicit_none_3.f08
@@ -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
diff --git a/gcc/testsuite/gfortran.dg/implicit_14.f90 b/gcc/testsuite/gfortran.dg/implicit_14.f90
index 8282c1f..422d913 100644
--- a/gcc/testsuite/gfortran.dg/implicit_14.f90
+++ b/gcc/testsuite/gfortran.dg/implicit_14.f90
@@ -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