Procedure Pointers: a first patch

Tobias Burnus burnus@net-b.de
Sun May 18 20:20:00 GMT 2008


Hi Janus,

Janus Weil wrote:
> I fixed this and the attached patch should apply without any 
> regressions. Of course it doesn't work for all kinds of procedure 
> pointers yet, but I will try to extend it further soon.
Nice. I assume you are looking for things which do not yet work ...
(besides "type t; procedure(), pointer :: procptr; end type t")


! rejects-valid:

intrinsic sin
procedure(real), pointer :: a
a => sin ! Error: Function 'sin' requires an argument list at (1)
end


! ice-on-invalid-code:

intrinsic sin
procedure(real), pointer :: a
a => sin(4.0) ! ICE in fold_convert, at fold-const.c:2527
end


! rejects-valid:

procedure(real), save, pointer :: a
                                  1
Error: PROCEDURE attribute conflicts with SAVE attribute in 'a' at (1)

"C1214 If a procedure entity has the INTENT attribute or SAVE attribute, 
it shall also have the POINTER attribute."



! rejects-valid:

procedure(one), pointer :: a => null()
                              1
Error: Initialization at (1) isn't for a pointer variable



! rejects-valid:

 external foo
 procedure(), pointer :: a
 a => foo
 call a()
 end
! Error: 'a' at (1) has a type, which is not consistent with the CALL at (2)



! rejects-valid:

integer :: i, foo
external foo
procedure(), pointer :: a
a => foo
i = a()
end
! Error: Can't convert PROCEDURE to INTEGER(4) at (1)



Additionally, the following program is accepted, although it is invalid:

interface
  elemental function one(a)
    real :: a, one
    intent(in) :: a
  end function one
  function two(a)
    real :: a, two
    intent(in) :: a
  end function two
end interface

procedure(one), pointer :: a
a => two
end


The program violates the following constrain which is not detected:

"7.4.2.2 Procedure pointer assignment" [...]
"If proc-pointer-object has an explicit interface, its characteristics 
shall be the same as proc-target except that proc-target may be pure 
even if proc-pointer-object is not pure and proc-target may be an 
elemental intrinsic procedure even if proc-pointer-object is not elemental.

"If the characteristics of proc-pointer-object or proc-target are such 
that an explicit interface is required, both proc-pointer-object and 
proc-target shall have an explicit interface.

"If proc-pointer-object has an implicit interface and is explicitly 
typed or referenced as a function, proc target shall be a function. If 
proc-pointer-object has an implicit interface and is referenced as a 
subroutine, proc-target shall be a subroutine.

"If proc-target and proc-pointer-object are functions, they shall have 
the same type; corresponding type parameters shall either both be 
deferred or both have the same value."




I believe the following program is thus invalid as the assumed-shape 
array requires an explicit interface:

external foo
interface
  subroutine bar(a)
     integer :: a(:)
  end subroutine bar
end interface
procedure(), pointer :: a
procedure(bar), pointer :: b
a => bar
b => foo
end


Tobias

PS: I think you should fix first the reject valid bugs. One could think 
of adding the checks for the constrains in a follow up patch. But if you 
like, you can also submit a single patch.



More information about the Fortran mailing list