Commit e35bbb23 by Janus Weil

re PR fortran/40164 (Fortran 2003: "Arrays of procedure pointers" (using PPCs))

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.

From-SVN: r147663
parent 9b2db7be
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>
* intrinsic.c (add_sym): Fix my last commit (r147655),
which broke bootstrap.
......
......@@ -2558,7 +2558,7 @@ gfc_match_rvalue (gfc_expr **result)
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;
......
......@@ -4840,6 +4840,9 @@ resolve_ppc_call (gfc_code* c)
if (!comp->attr.subroutine)
gfc_add_subroutine (&comp->attr, comp->name, &c->expr1->where);
if (resolve_ref (c->expr1) == FAILURE)
return FAILURE;
if (resolve_actual_arglist (c->ext.actual, comp->attr.proc,
comp->formal == NULL) == FAILURE)
return FAILURE;
......@@ -4869,6 +4872,9 @@ resolve_expr_ppc (gfc_expr* e)
if (!comp->attr.function)
gfc_add_function (&comp->attr, comp->name, &e->where);
if (resolve_ref (e) == FAILURE)
return FAILURE;
if (resolve_actual_arglist (e->value.function.actual, comp->attr.proc,
comp->formal == NULL) == FAILURE)
return FAILURE;
......@@ -9147,7 +9153,8 @@ resolve_fl_derived (gfc_symbol *sym)
&& sym != c->ts.derived)
add_dt_to_dt_list (c->ts.derived);
if (c->attr.pointer || c->attr.allocatable || c->as == NULL)
if (c->attr.pointer || c->attr.proc_pointer || c->attr.allocatable
|| c->as == NULL)
continue;
for (i = 0; i < c->as->rank; i++)
......
2009-05-18 Janus Weil <janus@gcc.gnu.org>
PR fortran/40164
* gfortran.dg/proc_ptr_comp_8.f90: New.
2009-05-18 Richard Guenther <rguenther@suse.de>
PR fortran/40168
......
! { dg-do run }
!
! PR 40164: Fortran 2003: "Arrays of procedure pointers" (using PPCs)
!
! Original test case by Barron Bichon <barron.bichon@swri.org>
! Adapted by Janus Weil <janus@gcc.gnu.org>
PROGRAM test_prog
ABSTRACT INTERFACE
FUNCTION fn_template(n,x) RESULT(y)
INTEGER, INTENT(in) :: n
REAL, INTENT(in) :: x(n)
REAL :: y(n)
END FUNCTION fn_template
END INTERFACE
TYPE PPA
PROCEDURE(fn_template), POINTER, NOPASS :: f
END TYPE PPA
TYPE ProcPointerArray
PROCEDURE(add), POINTER, NOPASS :: f
END TYPE ProcPointerArray
TYPE (ProcPointerArray) :: f_array(3)
PROCEDURE(add), POINTER :: f
real :: r
f_array(1)%f => add
f => f_array(1)%f
f_array(2)%f => sub
f_array(3)%f => f_array(1)%f
r = f(1.,2.)
if (abs(r-3.)>1E-3) call abort()
r = f_array(1)%f(4.,2.)
if (abs(r-6.)>1E-3) call abort()
r = f_array(2)%f(5.,3.)
if (abs(r-2.)>1E-3) call abort()
if (abs(f_array(1)%f(1.,3.)-f_array(3)%f(2.,2.))>1E-3) call abort()
CONTAINS
FUNCTION add(a,b) RESULT(sum)
REAL, INTENT(in) :: a, b
REAL :: sum
sum = a + b
END FUNCTION add
FUNCTION sub(a,b) RESULT(diff)
REAL, INTENT(in) :: a, b
REAL :: diff
diff = a - b
END FUNCTION sub
END PROGRAM test_prog
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment