Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
7 Views

Unspecified compile time error with function returning arrays

Hi there

here is the example:

Module Mod_1
  Type :: T_1
    integer :: n
    Integer, allocatable :: a(:)
  contains
    Procedure, Pass :: Init => SubInit
    Procedure, PAss :: getA => FunGetA
  End type T_1
  Interface
    Module Subroutine SubInit(this,n)
      Class(T_1), Intent(Inout) :: this
      Integer, Intent(in) :: n
    End Subroutine
    Module Function FunGetA(this)
      Class(T_1), Intent(Inout) :: this
      Integer, Dimension(size(this%a)) :: FunGetA
    End Function
  End Interface
End Module Mod_1

Submodule(Mod_1) Routines
contains
  Module Procedure SubInit
    Implicit None
    allocate(this%a(n))
  end Procedure
  Module Procedure FunGetA
    Implicit none
    if(allocated(this%a)) Then
      FunGetA=this%a
    End if
  End Procedure
End Submodule Routines

Program Test
  use Mod_1
  Implicit None
  Type(T_1) :: TA
  Integer, allocatable :: b(:)
  call TA%Init(5)
  b=TA%getA()
End Program Test

when compiling it chrashes with

SubMod_1.f90: catastrophic error: **Internal compiler error: segmentation violation signal raised** Please report this error along with the circumstances in which it occurred in a Software Problem Report.  Note: File and line given may not be explicit cause of this error.
compilation aborted for SubMod_1.f90 (code 1)
make: *** [makefile:31: SubMod_1.o] Error 1

The only workaround is to set the dimension specification in the interface definition of FunGetA to an integer value (eg. 10). Setting is to this%n causes the same crash.

Since I usually prefer subroutines I am not an expert in functions, so I might do something wrong here. But if it were obviously wrong I would expect a more informative compiler message.

Any idea.

Thanks

Karl

0 Kudos
1 Reply
Highlighted
Employee
7 Views

I reproduced the internal error and routed it to Development. I'll study the code further, but conformant or not, the internal error is unexpected.

(Internal tracking id: DPD200414401)

0 Kudos