Bug 109512 - accepts implicit dummy procedure even with "implicit none (external)"
Summary: accepts implicit dummy procedure even with "implicit none (external)"
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 12.2.0
: P4 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-04-14 13:03 UTC by Sébastien Villemot
Modified: 2023-05-28 04:15 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2023-04-14 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sébastien Villemot 2023-04-14 13:03:43 UTC
gfortran compiles the following source without error:

subroutine foo(bar)
  implicit none (external)
  call bar(1)
end subroutine foo

However my understanding is that it should reject it, because "bar" is an implicit dummy procedure, which is forbidden by "implicit none (external)".

Note that this is not the same issue as Bug 100972, which was not about dummy procedures.
Comment 1 kargls 2023-04-14 16:16:15 UTC
Confirmed.

8.7 IMPLICIT statement
...
An IMPLICIT NONE statement can indicate ..., or that external and
dummy procedures need to be explicitly given the EXTERNAL attribute.

'bar' is clearly a dummy procedure, so 'externa bar' is required.
Comment 2 kargls 2023-05-28 04:15:25 UTC
This patch catches the need for an external attribute.

diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index 6e42397c2ea..1e19712b413 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -3818,6 +3818,16 @@ resolve_call (gfc_code *c)
   /* Resume assumed_size checking.  */
   need_full_assumed_size--;
 
+  /* If 'implicit none (external)' and the symbol is a dummy argument,
+     check for an 'external' attribute.  */
+  if (csym->ns->has_implicit_none_export
+      && csym->attr.external == 0 && csym->attr.dummy == 1)
+    {
+      gfc_error ("Dummy procedure %qs at %C requires an EXTERNAL attribute",
+		 csym->name);
+      return false;
+    }
+
   /* If external, check for usage.  */
   if (csym && is_external_proc (csym))
     resolve_global_procedure (csym, &c->loc, 1);

A dejagnu-ified testcase.

! { dg-do compile }
subroutine foo(bar)
  implicit none (external)
  call bar(1)        ! { dg-error "requires an EXTERNAL attribute" }
end subroutine foo