Crash if temporary implicit pointer is created

Crash if temporary implicit pointer is created

Hi, 

Could you please explain the crash in the following program?

module A_m

	  implicit none

	  private

	  

	  type, public :: A_t

	    private

	    character(len=1)  :: dummy_char

	  contains

	    procedure :: DoSmth

	  end type
contains

	  subroutine DoSmth(this)

	    class(A_t), intent(in) :: this

	    write(*, "(A)") "A_t::DoSmth"

	  end subroutine DoSmth
end module A_m

	module B_m

	  use A_m

	  implicit none

	  private
  type, public :: B_t

	    private

	    class(A_t), pointer :: a => null()

	  contains

	    procedure :: GetA

	    procedure :: SetA

	  end type
contains

	  subroutine SetA(this, a)

	    class(B_t), intent(inout)         :: this

	    class(A_t), pointer, intent(in)   :: a

	    this%a => a

	  end subroutine SetA
  function GetA(this) result(a)

	    class(B_t), target, intent(in) :: this

	    class(A_t), pointer            :: a

	    a => this%a

	  end function GetA
end module B_m

	program main

	  use A_m

	  use B_m

	  implicit none

	  class(A_t), pointer :: a

	  class(B_t), pointer :: b

	  class(A_t), pointer :: a_ptr
  allocate(a, b)

	  call b%SetA(a)
  ! works with explicit pointer

	  a_ptr => b%GetA()

	  call DoA(a_ptr)
  ! crashes here

	  call DoA(b%GetA())
  deallocate(a, b)
contains

	  subroutine DoA(a)

	    class(A_t), pointer, intent(in) :: a

	    if (.not.associated(a)) then

	      write(*, "(A)") "error"

	    else

	      call a%DoSmth()

	    end if

	  end subroutine DoA
end program main

I believe that the program crashes because an implicit pointer is created at the statement "call DoA(b%GetA())".

Compiler version: XE 13.1

2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

I am looking at this now.

Steve - Intel Developer Support

Leave a Comment

Please sign in to add a comment. Not a member? Join today