Bug 54285 - [F03] Calling a PPC with proc-ptr result
Summary: [F03] Calling a PPC with proc-ptr result
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: ---
Assignee: janus
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-08-16 14:29 UTC by janus
Modified: 2012-09-17 12:52 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-08-17 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description janus 2012-08-16 14:29:51 UTC
The following (supposedly valid) test case ...


type :: t
  procedure(a), pointer, nopass :: p
end type

type(t) :: x
procedure(iabs), pointer :: pp

x%p => a

pp => x%p()  ! "Invalid character in name at (1)"

print *,pp(-3)

contains

  function a() result (b)
    procedure(iabs), pointer :: b
    b => iabs
  end function

end


triggers the error:

pp => x%p()
     1
Error: Invalid character in name at (1)
Comment 1 janus 2012-08-16 20:33:22 UTC
The following patch fixes the error message in comment 0:


Index: gcc/fortran/primary.c
===================================================================
--- gcc/fortran/primary.c	(revision 190419)
+++ gcc/fortran/primary.c	(working copy)
@@ -2004,8 +2004,7 @@ gfc_match_varspec (gfc_expr *primary, int equiv_fl
 
       primary->ts = component->ts;
 
-      if (component->attr.proc_pointer && ppc_arg
-	  && !gfc_matching_procptr_assignment)
+      if (component->attr.proc_pointer && ppc_arg)
 	{
 	  /* Procedure pointer component call: Look for argument list.  */
 	  m = gfc_match_actual_arglist (sub_flag,
@@ -2014,7 +2013,7 @@ gfc_match_varspec (gfc_expr *primary, int equiv_fl
 	    return MATCH_ERROR;
 
 	  if (m == MATCH_NO && !gfc_matching_ptr_assignment
-	      && !matching_actual_arglist)
+	      && !gfc_matching_procptr_assignment && !matching_actual_arglist)
 	    {
 	      gfc_error ("Procedure pointer component '%s' requires an "
 			 "argument list at %C", component->name);



However, with this one gets:

pp => x%p()
      1
Error: Interface mismatch in procedure pointer assignment at (1): 'p' has the wrong number of arguments

... which is obviously not true. Apparently the formal args of pp are compared to the formal args of x%p itself, and not to those of the result of x%p.
Comment 2 janus 2012-08-17 08:59:13 UTC
The error message mentioned in comment 1 can be fixed by this additional hunk:


Index: gcc/fortran/expr.c
===================================================================
--- gcc/fortran/expr.c	(revision 190419)
+++ gcc/fortran/expr.c	(working copy)
@@ -3504,8 +3504,16 @@ gfc_check_pointer_assign (gfc_expr *lvalue, gfc_ex
       comp = gfc_get_proc_ptr_comp (rvalue);
       if (comp)
 	{
-	  s2 = comp->ts.interface;
-	  name = comp->name;
+	  if (rvalue->expr_type == EXPR_FUNCTION)
+	    {
+	      s2 = comp->ts.interface->result;
+	      name = comp->ts.interface->result->name;
+	    }
+	  else
+	    {
+	      s2 = comp->ts.interface;
+	      name = comp->name;
+	    }
 	}
       else if (rvalue->expr_type == EXPR_FUNCTION)
 	{
Comment 3 janus 2012-08-17 11:00:26 UTC
The combined patches of comment 1 and 2 regtest cleanly.
Comment 4 janus 2012-09-17 12:50:40 UTC
Author: janus
Date: Mon Sep 17 12:50:34 2012
New Revision: 191383

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=191383
Log:
2012-09-17  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/54285
	* expr.c (gfc_check_pointer_assign): Correctly handle procedure pointers
	as function results.
	* primary.c (gfc_match_varspec): Allow to call a PPC with proc-ptr
	result.

2012-09-17  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/54285
	* gfortran.dg/proc_ptr_result_7.f90: New.

Added:
    trunk/gcc/testsuite/gfortran.dg/proc_ptr_result_7.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/expr.c
    trunk/gcc/fortran/primary.c
    trunk/gcc/testsuite/ChangeLog
Comment 5 janus 2012-09-17 12:52:27 UTC
Fixed on 4.8 trunk with r191383. Closing.