public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch, Fortran] PR33917 - PROCEDURE - check for interfaces from  later procedure-declaration-stmts
@ 2007-11-15 14:33 Tobias Burnus
  2007-11-15 18:02 ` Jerry DeLisle
  0 siblings, 1 reply; 2+ messages in thread
From: Tobias Burnus @ 2007-11-15 14:33 UTC (permalink / raw)
  To: 'fortran@gcc.gnu.org', gcc-patches; +Cc: Janus Weil

[-- Attachment #1: Type: text/plain, Size: 551 bytes --]

:ADDPATCH fortran:

PROCEDURE(<interface-name>) :: proc

allows for the interface either procedures with explicit interfaces
coming from an INTERFACE, or being host/use associated procedures.
Additionally, the interface name can also be declared in another
PROCEDURE-declaration statement - with the restriction that that
statement needs to come before the interface is used:

"C1212 (R1215) [...] If name is declared by a procedure-declaration-stmt it
shall be previously declared."


Build and regression tested on x86-64. Ok for the trunk?

Tobias

[-- Attachment #2: procedure.diff --]
[-- Type: text/plain, Size: 2908 bytes --]

2007-11-15  Tobias Burnus  <burnus@net-b.de>

	PR fortran/33917
	* decl.c (match_procedure_decl): Pre-resolve interface.
	* resolve.c (resolve_symbol): Reject interfaces later
	declared in procedure statements.

2007-11-15  Tobias Burnus  <burnus@net-b.de>

	PR fortran/33917
	* gfortran.dg/proc_decl_11.f90: New.

Index: gcc/fortran/decl.c
===================================================================
--- gcc/fortran/decl.c	(Revision 130194)
+++ gcc/fortran/decl.c	(Arbeitskopie)
@@ -3946,6 +3946,12 @@ match_procedure_decl (void)
   /* Various interface checks.  */
   if (proc_if)
     {
+      /* Resolve interface if possible. That way, attr.procedure is only set
+	 if it is declared by a later procedure-declaration-stmt, which is
+	 invalid per C1212.  */
+      while (proc_if->interface)
+	proc_if = proc_if->interface;
+
       if (proc_if->generic)
 	{
 	  gfc_error ("Interface '%s' at %C may not be generic", proc_if->name);
Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c	(Revision 130194)
+++ gcc/fortran/resolve.c	(Arbeitskopie)
@@ -7615,8 +7615,10 @@ resolve_symbol (gfc_symbol *sym)
   if (sym->attr.procedure && sym->interface
       && sym->attr.if_source != IFSRC_DECL)
     {
-      while (sym->interface->interface)
-	sym->interface = sym->interface->interface;
+      if (sym->interface->attr.procedure)
+	gfc_error ("Interface '%s', used by procedure '%s' at %L, is declared "
+		   "in a later PROCEDURE statement", sym->interface->name,
+		   sym->name,&sym->declared_at);
 
       /* Get the attributes from the interface (now resolved).  */
       if (sym->interface->attr.if_source || sym->interface->attr.intrinsic)
Index: gcc/testsuite/gfortran.dg/proc_decl_11.f90
===================================================================
--- gcc/testsuite/gfortran.dg/proc_decl_11.f90	(Revision 0)
+++ gcc/testsuite/gfortran.dg/proc_decl_11.f90	(Revision 0)
@@ -0,0 +1,34 @@
+! { dg-do compile }
+! PR fortran/33917
+!
+! Depending, in which order the symbol tree
+! was walked in resolve, gfortran resolved
+! p6 before p4; thus there was no explicit
+! interface available for p4 and an error
+! was printed. (This is a variant of proc_decl_2.f90)
+!
+! Additionally, the following contrain was not honoured:
+! "C1212 (R1215) [...] If name is declared by a procedure-declaration-stmt
+! it shall be previously declared." ("name" = interface-name)
+!
+program s
+  implicit none
+  procedure() :: q2
+  procedure() :: q3
+  procedure() :: q5
+  procedure(sub) :: p4
+  procedure(p4) :: p6
+contains
+  subroutine sub
+  end subroutine
+end program s
+
+subroutine test
+  implicit none
+  abstract interface
+    subroutine sub()
+    end subroutine sub
+  end interface
+  procedure(p4) :: p6 ! { dg-error "declared in a later PROCEDURE statement" }
+  procedure(sub) :: p4
+end subroutine test

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Patch, Fortran] PR33917 - PROCEDURE - check for interfaces from  later procedure-declaration-stmts
  2007-11-15 14:33 [Patch, Fortran] PR33917 - PROCEDURE - check for interfaces from later procedure-declaration-stmts Tobias Burnus
@ 2007-11-15 18:02 ` Jerry DeLisle
  0 siblings, 0 replies; 2+ messages in thread
From: Jerry DeLisle @ 2007-11-15 18:02 UTC (permalink / raw)
  To: Tobias Burnus; +Cc: 'fortran@gcc.gnu.org', gcc-patches, Janus Weil

Tobias Burnus wrote:
> :ADDPATCH fortran:
> 
> PROCEDURE(<interface-name>) :: proc
> 
> allows for the interface either procedures with explicit interfaces
> coming from an INTERFACE, or being host/use associated procedures.
> Additionally, the interface name can also be declared in another
> PROCEDURE-declaration statement - with the restriction that that
> statement needs to come before the interface is used:
> 
> "C1212 (R1215) [...] If name is declared by a procedure-declaration-stmt it
> shall be previously declared."
> 
> 
> Build and regression tested on x86-64. Ok for the trunk?
> 
> Tobias
> 

OK, thanks.

Jerry

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-11-15 15:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-11-15 14:33 [Patch, Fortran] PR33917 - PROCEDURE - check for interfaces from later procedure-declaration-stmts Tobias Burnus
2007-11-15 18:02 ` Jerry DeLisle

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).