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.
This commit is contained in:
Bernhard Reutner-Fischer 2021-10-31 17:44:45 +01:00
parent c64ca0e7bb
commit 1727bb533e
4 changed files with 32 additions and 2 deletions

View 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 ();

View 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;

View File

@ -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

View 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