This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[Patch, Fortran] PR33945 - PROCEDURE / MODULE PROCEDURE fixes
- From: Tobias Burnus <burnus at net-b dot de>
- To: "'fortran at gcc dot gnu dot org'" <fortran at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>, Janus Weil <jaydub66 at googlemail dot com>
- Date: Thu, 08 Nov 2007 15:29:17 +0100
- Subject: [Patch, Fortran] PR33945 - PROCEDURE / MODULE PROCEDURE fixes
:ADDPATCH fortran:
MODULE PROCEDURE may only be used with module procedures (nomen est
omen). However, with PROCEDURE on can declare a procedure with an
explicit interface, which is external and thus not a module procedure.
These were not rejected.
By contrast, PROCEDURE in a generic interface body may be used with any
procedure, having an explicit interface. Currently, procedures declared
with the PROCEDURE statement are rejected.
For module procedure the solution is to simply add a check. For
procedure, one simply does not set the attribute in the generic
interface. (As one only uses a symbol and does not declare it, this
should be the right fix and not a hack.)
Build and regtested on x86-64. Ok for the trunk?
Tobias
2007-11-08 Tobias Burnus <burnus@net-b.de>
PR fortran/33917
* interface.c (check_sym_interfaces): Disallow PROCEDURE-declared
procedures for MODULE PROCEDURE.
* decl.c (match_procedure_in_interface): Do not mark as procedure.
2007-11-08 Tobias Burnus <burnus@net-b.de>
PR fortran/33917
* gfortran.dg/proc_decl_5.f90: New.
* gfortran.dg/proc_decl_6.f90: New.
Index: gcc/fortran/interface.c
===================================================================
--- gcc/fortran/interface.c (Revision 129892)
+++ gcc/fortran/interface.c (Arbeitskopie)
@@ -1137,7 +1137,9 @@ check_sym_interfaces (gfc_symbol *sym)
for (p = sym->generic; p; p = p->next)
{
- if (p->sym->attr.mod_proc && p->sym->attr.if_source != IFSRC_DECL)
+ if (p->sym->attr.mod_proc
+ && (p->sym->attr.if_source != IFSRC_DECL
+ || p->sym->attr.procedure))
{
gfc_error ("'%s' at %L is not a module procedure",
p->sym->name, &p->where);
Index: gcc/fortran/decl.c
===================================================================
--- gcc/fortran/decl.c (Revision 129892)
+++ gcc/fortran/decl.c (Arbeitskopie)
@@ -4091,8 +4091,6 @@ match_procedure_in_interface (void)
if (gfc_add_interface (sym) == FAILURE)
return MATCH_ERROR;
- sym->attr.procedure = 1;
-
if (gfc_match_eos () == MATCH_YES)
break;
if (gfc_match_char (',') != MATCH_YES)
Index: gcc/testsuite/gfortran.dg/proc_decl_5.f90
===================================================================
--- gcc/testsuite/gfortran.dg/proc_decl_5.f90 (Revision 0)
+++ gcc/testsuite/gfortran.dg/proc_decl_5.f90 (Revision 0)
@@ -0,0 +1,28 @@
+! { dg-do run }
+! PR fortran/33945
+!
+! PROCEDURE in the interface was wrongly rejected
+module modproc
+ implicit none
+ interface bar
+ procedure x
+ end interface bar
+ procedure(sub) :: x
+ interface
+ integer function sub()
+ end function sub
+ end interface
+end module modproc
+
+integer function x()
+ implicit none
+ x = -5
+end function x
+
+program test
+ use modproc
+ implicit none
+ print *, x()
+end program test
+
+! { dg-final { cleanup-modules "modproc" } }
Index: gcc/testsuite/gfortran.dg/proc_decl_6.f90
===================================================================
--- gcc/testsuite/gfortran.dg/proc_decl_6.f90 (Revision 0)
+++ gcc/testsuite/gfortran.dg/proc_decl_6.f90 (Revision 0)
@@ -0,0 +1,17 @@
+! { dg-do compile }
+! PR fortran/33945
+!
+! MODULE PROCEDURE in the interface was wrongly accepted
+module modproc2
+ implicit none
+ interface
+ subroutine x
+ end subroutine x
+ end interface
+ procedure(x) :: y
+ interface bar
+ module procedure y ! { dg-error "not a module procedure" }
+ end interface bar
+end module modproc2
+
+end