]> 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>
Wed, 22 Mar 2023 17:56:10 +0000 (18:56 +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.

(cherry picked from commit dd282b16bfd3c6e218dffb7798a375365b10ae22)

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

index b640051473112af20b23954a0f58670426e34ef0..b89ed17be50413da9783cd7faf0687431afb5672 100644 (file)
@@ -9984,9 +9984,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