]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: reject MODULE PROCEDURE outside generic module interface [PR99036]
authorHarald Anlauf <anlauf@gmx.de>
Tue, 21 Mar 2023 18:58:31 +0000 (19:58 +0100)
committerHarald Anlauf <anlauf@gmx.de>
Tue, 21 Mar 2023 19:00:32 +0000 (20:00 +0100)
gcc/fortran/ChangeLog:

PR fortran/99036
* decl.cc (gfc_match_modproc): Reject MODULE PROCEDURE if not in a
generic module interface.

gcc/testsuite/ChangeLog:

PR fortran/99036
* gfortran.dg/pr99036.f90: New test.

gcc/fortran/decl.cc
gcc/testsuite/gfortran.dg/pr99036.f90 [new file with mode: 0644]

index c8f0bb83c2c6103a9bdf81a021493389c1ac58b1..233bf244d62150fc379dfa2bd51f767d660a107c 100644 (file)
@@ -9995,9 +9995,10 @@ gfc_match_modproc (void)
   gfc_namespace *module_ns;
   gfc_interface *old_interface_head, *interface;
 
-  if ((gfc_state_stack->state != COMP_INTERFACE
-       && gfc_state_stack->state != COMP_CONTAINS)
-      || gfc_state_stack->previous == NULL
+  if (gfc_state_stack->previous == NULL
+      || (gfc_state_stack->state != COMP_INTERFACE
+         && (gfc_state_stack->state != COMP_CONTAINS
+             || gfc_state_stack->previous->state != COMP_INTERFACE))
       || current_interface.type == INTERFACE_NAMELESS
       || current_interface.type == INTERFACE_ABSTRACT)
     {
diff --git a/gcc/testsuite/gfortran.dg/pr99036.f90 b/gcc/testsuite/gfortran.dg/pr99036.f90
new file mode 100644 (file)
index 0000000..a6e396f
--- /dev/null
@@ -0,0 +1,9 @@
+! { dg-do compile }
+! PR fortran/99036 - ICE in gfc_current_interface_head
+! Contributed by G. Steinmetz
+
+module m
+contains
+  module procedure s ! { dg-error "must be in a generic module interface" }
+  end
+end