Hi there, the code below compiles and runs without error:
Module Mod_Bla Implicit none Type :: bla Real, Allocatable, Private :: aa(:,:) contains Private Generic, Public :: getaa => getaamatrix, getaaelement Procedure, Pass :: getaamatrix => fungetaamatrix Procedure, Pass :: getaaelement => fungetaaelement Procedure, Pass, Public :: set => SubSet end type bla Interface Module Subroutine SubSet(this,RMIn) Implicit none Class(bla), Intent(InOut), Target :: this Real, Intent(In) :: RMIn(:,:) End Subroutine Module Function FunGetAaMatrix(this) Class(bla), Intent(In), Target :: this Real, Pointer :: FunGetAAMatrix(:,:) end Function Module Function FunGetAaElement(this,rowpos,colpos) Class(bla), Intent(In), Target :: this Integer, Intent(In) :: rowpos, colpos Real, Pointer :: FunGetAAElement end Function End Interface End Module Mod_Bla Submodule(Mod_Bla) GetSet contains Module Procedure SubSet Implicit none Allocate(this%aa,source=RMIn) End Procedure Module Procedure FunGetAAMatrix Implicit none FunGetAAMatrix=>this%aa End Procedure Module Procedure FunGetAAElement Implicit none FunGetAAElement=>this%aa(rowpos,colpos) End Procedure End Submodule GetSet Program Test use Mod_bla Type(bla), Target :: xx Class(*), Pointer :: zzz Real, Pointer :: y Real, Allocatable :: bb(:,:) Integer :: i Allocate(bb(3,3)) Do i=1,3 bb(i,:)=i end do zzz=>xx Select Type(xxx=>zzz) Class Is(bla) call xxx%set(bb) y=>xxx%getaa(2,2) !!y=xxx%getaa(2,2) End Select End Program Test
However, if the pointer assigment in the fourth line (counted from the end) is commented and the line below is uncommented, it still compiles without error but yields a segfault at runtime. From my understanding that line could be interpreted as sourced allocation (which is not possible for pointers from my understanding), but the funtion returns a pointer which results in a segfault (this also happens with gfortran). But this is already obvious at compile time. Am I wrong or is this a compiler bug / improper defined in the standard??
Thanks
ifort version 17.1 on linux kernel 4.8.13