Hello Fortran community,
I’ve stumbled upon an unexpected gfortran runtime error stop when using a non-associated procedure pointer as optional
argument to a subroutine
module m
abstract interface
! Just a function interface
subroutine my_fun(x)
real, intent(in) :: x
end subroutine my_fun
end interface
contains
! Optional function argument
subroutine with_fun(sub)
procedure(my_fun), optional :: sub
print *, present(sub)
end subroutine
end module m
program p
use m
procedure(my_fun), pointer :: ptr => null()
call with_fun() ! no runtime error
call with_fun(sub=ptr) ! runtime error
end
- The error is triggered usin
-fcheck=all
- It is not triggered when a data pointer is passed rather than a procedure pointer.
I believe it is of course correct to check this when the procedure argument is not optional
, but probably it should not be, when optional
(this is what happens for variable pointers)
Do you think this issue may be submitted to the GNU bugzilla? IMHO this is a minor bug related to an overlooked check that may be worthwhile of lifting.
Here I’ve put an example that shows no error triggered on the data, error triggered on the null()
procedure.
All gfortran versions seem to be affected by this issue, so most likely there is a Standard-related reason that check is still in place.