How to do user defined type that includes parameterized derived type with gfortran?

68 Views Asked by At

I am learning how to use parameterized derived type in fortran. My aim is to create a user defined type that contains a parameterized derived type with length deferred. And I have a lot of problems. (Rq : compiler : gfortran)

First, I got an internal compilation error with this program.

program main

implicit none

type :: square_mat_t(mat_size) 
    integer, len :: mat_size
    real, dimension(mat_size,mat_size) :: mat
end type square_mat_t

type :: two_sqmat_t(mat_size)
    integer, len :: mat_size
    type(square_mat_t(mat_size)) :: mat1
    type(square_mat_t(mat_size)) :: mat2
end type two_sqmat_t

type(two_sqmat_t(:)), allocatable :: my_twosqmat2

end program main

But if type(two_sqmat_t(2)) :: my_twosqmat1 is added before my_twosqmat2 declaration, it compiles.

...
type(two_sqmat_t(2)) :: my_twosqmat1
type(two_sqmat_t(:)), allocatable :: my_twosqmat2
...

So I decided to try to init my_twosqmat1 (I will see later for my_twosqmat2)

my_twosqmat1%mat1%mat(:,:) = 1

And I got another compilation error.

These are the error messages:

First error:

f951: internal compiler error: Segmentation fault 

Second error:

extend_param_derived_type.f90:21:16: 21 | end program main | 1 internal compiler error: Segmentation fault – 

So, I wonder how it is possible to write a program with an user defined type that includes a parameterized derived type using the gfortran compiler. A simple example would be welcome.

0

There are 0 best solutions below