The Intel Parallel Studio XE 2017 Fortran compiler produces code which crashes with omitted optional intent out arguments of an abstract type.
The previous version of the compiler did not have this problem:
forrtl: severe (157): Program Exception - access violation
program prog use sub_module use simple_exception_module implicit none type(simple_exception_type) :: exception character(:), allocatable :: message call sub( exception ) if ( exception%catch( message ) ) then write(*,*) message end if call sub() ! crashes here end program prog module sub_module use exception_module implicit none contains subroutine sub( exception ) class(exception_type), intent(out), optional :: exception if ( present( exception ) ) then call exception%throw( 'Exception in sub' ) end if end subroutine sub end module sub_module module simple_exception_module use exception_module implicit none private type, extends(exception_type), public :: simple_exception_type character(:), allocatable, private :: message contains procedure :: throw procedure :: catch end type simple_exception_type contains subroutine throw( exception, message ) class(simple_exception_type), intent(inout) :: exception character(*), intent(in) :: message exception%message = message end subroutine throw logical function catch( exception, message ) class(simple_exception_type), intent(inout) :: exception character(:), allocatable, intent(out) :: message if ( allocated( exception%message ) ) then message = exception%message catch = .true. else catch = .false. end if end function catch end module simple_exception_module module exception_module implicit none type, abstract :: exception_type contains procedure(throw_proc), deferred :: throw procedure(catch_proc), deferred :: catch end type exception_type abstract interface subroutine throw_proc( exception, message ) import class(exception_type), intent(inout) :: exception character(*), intent(in) :: message end subroutine throw_proc end interface abstract interface logical function catch_proc( exception, message ) import class(exception_type), intent(inout) :: exception character(:), allocatable, intent(out) :: message end function catch_proc end interface end module exception_module
Thanks - I can reproduce this and will send it on to the developers. Issue ID DPD200414727
I expect this bug to be fixed in Update 2 to Parallel Studio XE 2017.
For more complete information about compiler optimizations, see our Optimization Notice.