Quantcast
Viewing all articles
Browse latest Browse all 415

Type casting regression in ifort2018 beta

The following code segfaults because the explicit allocation in the type casting does not work any more with ifort2018 beta. I filed a bug report already. A workaround is given.

module event_base
  implicit none
  private
  public :: event_callback_t
  public :: event_callback_nop_t
  public :: eio_callback_t
  public :: dispatch

  type, abstract :: event_callback_t
     private
  end type event_callback_t

  type, extends (event_callback_t) :: event_callback_nop_t
     private
  end type event_callback_nop_t

  type, abstract :: generic_event_t
     real, dimension(:), allocatable :: sqme
  end type generic_event_t

  type :: eio_callback_t
     class(event_callback_t), allocatable :: callback
   contains
     procedure :: set_parameters => eio_callback_set_parameters  
  end type eio_callback_t

contains

  subroutine eio_callback_set_parameters (eio, callback, i)
    class(eio_callback_t), intent(inout) :: eio
    class(event_callback_t), intent(in) :: callback
    integer, intent(in) :: i
    allocate (eio%callback, source = callback)
  end subroutine eio_callback_set_parameters

  subroutine dispatch (eio, event_callback)
    type(eio_callback_t), intent(inout) :: eio
    class(event_callback_t), allocatable, intent(in) :: event_callback
    !!! Workaround:
    ! type(event_callback_nop_t) :: tmp
    if (allocated (event_callback)) then
       call eio%set_parameters (event_callback, 1)
    else
       call eio%set_parameters (event_callback_nop_t (), 0)
       ! call eio%set_parameters (tmp, 0)
    end if
  end subroutine dispatch

end module event_base

program main
  use event_base

  type(eio_callback_t) :: eio
  class(event_callback_t), allocatable :: foo
  call dispatch (eio, foo)

end program main

 


Viewing all articles
Browse latest Browse all 415

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>