Bug 39946 - PROCEDURE statements: interface with RESULT variable
Summary: PROCEDURE statements: interface with RESULT variable
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: ---
Assignee: janus
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2009-04-28 14:39 UTC by janus
Modified: 2009-04-28 16:31 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2009-04-28 14:52:49


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description janus 2009-04-28 14:39:44 UTC
The following program


  procedure(prc_is_allowed), pointer :: fptr

  interface
     function prc_is_allowed (flv, hel, col) result (is_allowed)
       logical :: is_allowed
       integer, intent(in) :: flv, hel, col
     end function prc_is_allowed
  end interface

  fptr => prc_is_allowed

end


currently fails with

  fptr => prc_is_allowed
          1
Error: Interfaces don't match in procedure pointer assignment at (1)

which is nonsense, of course. This seems to be due to a bug in the implementation of PROCEDURE statements and was only discovered after PR39735 was fixed (checking of return values in procedure pointer assignments). The test case was provided by Juergen Reuter.
Comment 1 janus 2009-04-28 14:52:49 UTC
Here's a patch:

Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c	(Revision 146879)
+++ gcc/fortran/resolve.c	(Arbeitskopie)
@@ -9244,7 +9244,10 @@ resolve_symbol (gfc_symbol *sym)
 	  if (ifc->attr.intrinsic)
 	    resolve_intrinsic (ifc, &ifc->declared_at);
 
-	  sym->ts = ifc->ts;
+	  if (ifc->result)
+	    sym->ts = ifc->result->ts;
+	  else   
+	    sym->ts = ifc->ts;
 	  sym->ts.interface = ifc;
 	  sym->attr.function = ifc->attr.function;
 	  sym->attr.subroutine = ifc->attr.subroutine;
Comment 2 janus 2009-04-28 16:27:47 UTC
Subject: Bug 39946

Author: janus
Date: Tue Apr 28 16:27:27 2009
New Revision: 146905

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=146905
Log:
2009-04-28  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/39946
	* resolve.c (resolve_symbol): Correctly copy the interface of a
	PROCEDURE statement if the interface involves a RESULT variable.


2009-04-28  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/39946
	* gfortran.dg/proc_ptr_16.f90: New.


Added:
    trunk/gcc/testsuite/gfortran.dg/proc_ptr_16.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/resolve.c
    trunk/gcc/testsuite/ChangeLog

Comment 3 janus 2009-04-28 16:31:03 UTC
Fixed with r146905. Closing.