This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: Procedure Pointers: a first patch
Hi Janus,
I have some more things, which fail. Maybe it makes sense to check-in a
half-finished patch and continue with the fixing of the smaller items
later. But one can also wait until everything works. (In any case, one
should first finish this part before one starts working on proc pointers
as derived-type components.)
Tobias
Tobias Burnus wrote:
Here are some things which do not work:
implicit none
interface
subroutine bar()
end subroutine bar
end interface
pointer :: bar
foo => bar
end
gives the error:
Error: Unexpected use of subroutine name 'bar' at (1)
The example is wrong (and the error message OK). The correct test should be:
implicit none
external foo
interface
subroutine bar()
end subroutine bar
end interface
pointer :: bar
bar => foo
end
Error: 'bar' at (1) is not a variable
* * *
Some more related things I found:
procedure(), pointer :: x
common /com/ x
end
Error: PROCEDURE attribute of 'x' conflicts with VARIABLE attribute at (1)
R558 common-block-object is variable-name [ ( explicit-shape-spec-list ) ]
or proc-pointer-name
* * *
Add a test case that "allocate(procptr)" fails. (It currently correctly
gives an error.)
* * *
We need to check (e.g. via c.l.f or by studying the standard) whether
the following is valid or not:
procedure(), pointer :: x
procedure(x), pointer :: y
end
It is currently rejected, but the error message is highly misleading. Is
this program valid or invalid?
* * *
The following program should be rejected:
intrinsic sin
call foo(sin)
contains
subroutine foo(x)
procedure(), pointer :: x
end subroutine foo
end
"If a dummy argument is a procedure pointer, the associated actual
argument shall be a procedure pointer, a reference to a function that
returns a procedure pointer, or a reference to the NULL intrinsic
function." (12.4.1.3)
* * *
procedure(), pointer :: p
call foo(null(p))
contains
subroutine foo(x)
procedure(), pointer :: x
end subroutine foo
end
Error: 'mold' argument of 'null' intrinsic at (1) must be a POINTER
If you are there, you can also fix:
use iso_c_binding
type(c_funptr)::p
call foo(null(p))
contains
subroutine foo(x)
type(c_funptr) :: x
end subroutine foo
end
and also the same for type(c_ptr).
* * *
integer, pointer :: p
call foo(p)
contains
subroutine foo()
procedure(), pointer :: x
end subroutine foo
end
I think the error message could be more helpful:
Error: Type mismatch in argument 'x' at (1); passed INTEGER(4) to UNKNOWN
"UNKNOWN" could be "PROC POINTER" ?!?
* * *
use iso_c_binding
implicit none
type(c_ptr) :: cptr
!type(c_funptr) :: cptr
integer,pointer :: fptr
!procedure(),pointer::fptr
call c_f_procpointer(cptr,fptr)
end
Here both cptr and fptr are of the wrong type, but they are still
accepted (and might give an ICE).
Analogously, the following is invalid:
use iso_c_binding
implicit none
type(c_funptr) :: cptr
integer,pointer :: fptr
call c_f_pointer(cptr,fptr)
end