Bug 40164 - Fortran 2003: "Arrays of procedure pointers" (using PPCs)
Summary: Fortran 2003: "Arrays of procedure pointers" (using PPCs)
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-05-15 18:22 UTC by janus
Modified: 2009-05-18 14:47 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2009-05-15 21:51:18


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description janus 2009-05-15 18:22:42 UTC
PROGRAM test_prog

 TYPE ProcPointerArray
   PROCEDURE(add), POINTER, NOPASS :: f
 END TYPE ProcPointerArray

 TYPE (ProcPointerArray) :: f_array(1)
 PROCEDURE(add), POINTER :: f

 f_array(1)%f => add
 f => f_array(1)%f
 PRINT*, f(2.,4.)

CONTAINS

 FUNCTION add(a,b) RESULT(sum)
   REAL, INTENT(in) :: a, b
   REAL :: sum
   sum = a + b
 END FUNCTION add

END PROGRAM test_prog


This produces the error

 f => f_array(1)%f
                1
Error: VARIABLE attribute of 'f_array' conflicts with PROCEDURE attribute at (1)

Reported by Barron Bichon.
Comment 1 janus 2009-05-15 21:51:16 UTC
Here is a small patch which fixes the test case:

Index: gcc/fortran/primary.c
===================================================================
--- gcc/fortran/primary.c	(revision 147527)
+++ gcc/fortran/primary.c	(working copy)
@@ -2558,7 +2558,7 @@
       if (gfc_matching_procptr_assignment)
 	{
 	  gfc_gobble_whitespace ();
-	  if (gfc_peek_ascii_char () == '(')
+	  if (!sym->attr.dimension && gfc_peek_ascii_char () == '(')
 	    /* Parse functions returning a procptr.  */
 	    goto function0;
 
Comment 2 janus 2009-05-16 14:09:50 UTC
Adding in the test case a line like

 print *, f_array(1)%f(3.,5.)

produces a segfault in gfc_conv_scalarized_array_ref (trans-array.c, 2414).
Comment 3 janus 2009-05-18 14:45:20 UTC
Subject: Bug 40164

Author: janus
Date: Mon May 18 14:44:55 2009
New Revision: 147663

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

	PR fortran/40164
	* primary.c (gfc_match_rvalue): Handle procedure pointer components in
	arrays.
	* resolve.c (resolve_ppc_call,resolve_expr_ppc): Resolve component and
	array references.
	(resolve_fl_derived): Procedure pointer components are not required to
	have constant array bounds in their return value.


2009-05-18  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/40164
	* gfortran.dg/proc_ptr_comp_8.f90: New.


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

Comment 4 janus 2009-05-18 14:47:05 UTC
Fixed with r147663. Closing.