I came across this question on Stackoverflow, which asks about segmentation fault when using an optional class dummy argument. Although the question itself seems to have been solved (by changing class
to type
), this might be a possible compiler issue, so anyway I am reporting here:
A minimum reproducible example is like this:
module test_m
implicit none
type :: error_t
end type
contains
subroutine throw( stat )
type(error_t), optional :: stat
end
subroutine test_throw( stat )
class(error_t), optional :: stat
call throw( stat )
end
end
program main
use test_m, only: error_t, test_throw
implicit none
type(error_t) :: stat
call test_throw() !! segfault(gfort-10.2 -O0 or no option)
!call test_throw(stat) !! ok
end
Segmentation fault goes away when compiling with optimization flags >= -O1
.