]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: name conflict between internal procedure and derived type [PR104351]
authorHarald Anlauf <anlauf@gmx.de>
Wed, 11 Oct 2023 19:29:35 +0000 (21:29 +0200)
committerHarald Anlauf <anlauf@gmx.de>
Fri, 13 Oct 2023 16:54:53 +0000 (18:54 +0200)
gcc/fortran/ChangeLog:

PR fortran/104351
* decl.cc (get_proc_name): Extend name conflict detection between
internal procedure and previous declaration also to derived type.

gcc/testsuite/ChangeLog:

PR fortran/104351
* gfortran.dg/derived_function_interface_1.f90: Adjust pattern.
* gfortran.dg/pr104351.f90: New test.

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

index 4a3c5b86de007a464c2a9df5209adcb2568ed232..bdd3be32a4685b1edee0301bd5e2fb831acdf14c 100644 (file)
@@ -1404,7 +1404,9 @@ get_proc_name (const char *name, gfc_symbol **result, bool module_fcn_entry)
       /* Trap declarations of attributes in encompassing scope.  The
         signature for this is that ts.kind is nonzero for no-CLASS
         entity.  For a CLASS entity, ts.kind is zero.  */
-      if ((sym->ts.kind != 0 || sym->ts.type == BT_CLASS)
+      if ((sym->ts.kind != 0
+          || sym->ts.type == BT_CLASS
+          || sym->ts.type == BT_DERIVED)
          && !sym->attr.implicit_type
          && sym->attr.proc == 0
          && gfc_current_ns->parent != NULL
index 24a009509128f9ba121370cbd031ef567042ad8e..5438ad49c6acb606111f9a2d7cdfa7c87dd58ee5 100644 (file)
@@ -38,7 +38,7 @@ end function ext_fun
 
 contains
 
-  type(foo) function fun() ! { dg-error "already has an explicit interface" }
+  type(foo) function fun() ! { dg-error "has an explicit interface" }
   end function fun  ! { dg-error "Expecting END PROGRAM" }
 
 end
diff --git a/gcc/testsuite/gfortran.dg/pr104351.f90 b/gcc/testsuite/gfortran.dg/pr104351.f90
new file mode 100644 (file)
index 0000000..86b47e0
--- /dev/null
@@ -0,0 +1,14 @@
+! { dg-do compile }
+! PR fortran/104351
+! Contributed by G.Steinmetz
+
+program p
+  implicit none
+  type t
+  end type
+  type(t) :: f
+contains
+  real function f() result(z) ! { dg-error "has an explicit interface" }
+    z = 0.0                   ! { dg-error "assignment" }
+  end function f              ! { dg-error "Expecting END PROGRAM" }
+end