Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Copy extended types gives access violation

Lars_Jakobsen
Beginner
290 Views

Hi

I get an access violation when I try to copy one extended structure to another:

"forrtl: severe (157): Program Exception - access violation"

If I use ordinary "types", then this works fine.

Am I not allowed to copy one extended type to another? Is there are workaround?

I am using the Intel Visual Fortran Compiler v. 16.0.

    program Console1

    implicit none

    ! Variables
    integer, parameter :: DP=8
    integer, parameter :: MAXNAMELENGTH=10

!-- BASIC TYPE
    type :: T_BASIC(n)
      integer, len                    :: n=MAXNAMELENGTH  !length of nam (defaults to MAXNAMELENGTH)
      character(len=n)                :: nam    !name
      integer                         :: iPoi   !internal pointer
    end type T_BASIC

    
!-- beam appurtenance properties 
    type, extends(T_BASIC) :: T_prtapp    !<- **** this will lead to trouble ****
!    type :: T_prtapp                     !<- **** this will work            ****
      integer                                         :: Tp
    end type T_prtapp
    
!-- beam appurtenances (actual appurtenances as used)
    type :: T_bapp
      type (T_prtapp)                                 :: prt     !appurtenance properties for this beam appurtenance
      
    end type T_bapp
    
!-- Global data
    type :: T_G
      type(T_prtapp), dimension(:), allocatable         :: prtapp  !appurtenance properties
      integer                                           :: nprtapp !number of appurtenance properties
      
      type(T_bapp), dimension(:), allocatable           :: Bapp     !beam appurtenances
      integer                                           :: nBApp    !number of beam appurtenances
      
    end type T_G
    type(T_G) :: G
    integer   :: iret
    
    
    ! Body of Console1
    G%nprtapp = 5
    allocate(G%prtapp(G%nprtapp))
    
    G%nBapp = 3
    allocate(G%Bapp(G%nBapp))
    
    G%Bapp(1)%prt = G%prtapp(1)   !<- this throws the error 

    iret = 1
    
    
    end program Console1

Best regards

Lars

0 Kudos
3 Replies
Steven_L_Intel1
Employee
290 Views

I can reproduce this in 16.0.3 but not in the current version 17.0.0. Please upgrade.

0 Kudos
Andrew_Smith
New Contributor III
290 Views

I was able to create default assignment code to make it work. But the area of parameterized derived types has been problematic and if Steve says use latest compiler then it certainly is good advice.

module myType
   implicit none
   
   integer, parameter :: DP=8
   integer, parameter :: MAXNAMELENGTH=10

   type :: T_BASIC(n)
      integer, len     :: n=MAXNAMELENGTH
      character(len=n) :: nam
      integer          :: iPoi
   end type

   type, extends(T_BASIC) :: T_prtapp
      integer             :: Tp
   end type

   type :: T_bapp
     type (T_prtapp) :: prt
   end type

   type :: T_G
     type(T_prtapp), dimension(:), allocatable :: prtapp
     integer                                   :: nprtapp
     type(T_bapp), dimension(:), allocatable   :: Bapp
     integer                                   :: nBApp
   end type

   interface assignment(=)
      module procedure assignT_Basic
      module procedure assignT_prtapp
   end interface
   
contains

   elemental subroutine assignT_Basic(b, a)
      type(T_Basic(*)), intent(in) :: a
      type(T_Basic(*)), intent(inout) :: b
      b%nam = a%nam
      b%iPoi = a%iPoi
   end
   
   elemental subroutine assignT_prtapp(b, a)
      type(T_prtapp), intent(in) :: a
      type(T_prtapp), intent(inout) :: b
      b%T_Basic = a%T_Basic
      b%Tp = a%Tp
   end

end module

program Console1
   use myType
   implicit none

   type(T_G) :: G
   integer   :: iret

   G%nprtapp = 5
   allocate(G%prtapp(G%nprtapp))
   G%nBapp = 3
   allocate(G%Bapp(G%nBapp))
   G%Bapp(1)%prt = G%prtapp(1)   !<- this now works
   iret = 1
end program

 

0 Kudos
Lars_Jakobsen
Beginner
290 Views

I have upgraded to version 17 and it now seem to work.

Thank you both for the quick response.

Lars

 

0 Kudos
Reply