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

Class Pointer within an array of a type produces wrong results

thomas_boehme
New Contributor II
429 Views

The code below outputs a wrong value for List1(1)%Ptr%Val. This only happens, if the type (List) is used as an array.
If it is used as a single element, everything is fine. Unless I am missing something, I think this is a compiler bug.

Best regards,
Thomas

[plain]PROGRAM CLASSPTR

  TYPE :: BaseType
    REAL(8) :: val
  END TYPE


  TYPE :: List
    CLASS (BaseType), POINTER :: Ptr
  END TYPE
  
  TYPE (BaseType), TARGET :: Base1
  CLASS (BaseType), POINTER :: BasePtr
  TYPE (List) ::  List1(5)  
    
  Base1%val = 34.123d0
  List1(1)%Ptr => Base1
  BasePtr => Base1
    
  Write (*,*) BasePtr%Val, List1(1)%Ptr%Val

END PROGRAM[/plain]
0 Kudos
2 Replies
thomas_boehme
New Contributor II
429 Views

Things get even worse when I copy the array into another one. The code below does result in an access violation upon the write (/assume:realloc_lhs is on) when compiled with Release option.

regards,
Thomas

[plain]PROGRAM CLASSPTR

  TYPE :: BaseType
    REAL(8) :: val
  END TYPE


  TYPE :: List
    CLASS (BaseType), POINTER :: Ptr
  END TYPE
  
  TYPE (BaseType), TARGET :: Base1
  CLASS (BaseType), POINTER :: BasePtr
  TYPE (List), ALLOCATABLE ::  List1(:), List2(:)  
    
    
  Base1%val = 34.123d0
  ALLOCATE(List1(1))
  List1(1)%Ptr => Base1
  List2 = List1
  BasePtr => Base1
    
  Write (*,*) BasePtr%Val, List1(1)%Ptr%Val, List2(1)%Ptr%Val

END PROGRAM[/plain]
0 Kudos
Steven_L_Intel1
Employee
429 Views
Thanks - we'll look into it.
0 Kudos
Reply