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

Access violation when accessing type-bound procedures in an array of a type when passed to subroutine as class array

thomas_boehme
New Contributor II
689 Views
I just noticed another problem related to type-bound procedures.

When I declare an array of type tBase and pass it to a subroutine which expects an array of CLASS tBase, I am unable to call any type-bound procedures within the subroutine. They all result in an access violation.

See example code for details. The access violations occurs upon calling the type-bound procedure Test(). (Note that the crash occurs when using ArrPtr(1)%Test directly or via another class pointer Ptr%Test() ).

I have to admit that the construct is somewhat weird, but Idon't see why it should not be allowed.

regards,
Thomas

[plain]  module Types
    TYPE :: tBase
      INTEGER :: valBase
      CONTAINS
        PROCEDURE Test
    END TYPE
    
   CONTAINS
      SUBROUTINE TBProblem(ArrPtr)
        CLASS (tBase), INTENT(INOUT), TARGET :: ArrPtr(:)
        CLASS (tBase), POINTER :: Ptr
        Ptr => ArrPtr(1)
        CALL Ptr%Test()
      END SUBROUTINE
      SUBROUTINE Test(this)
        CLASS (tBase), INTENT(INOUT) :: this
        END SUBROUTINE Test
   end module

    program TypeBoundProcedures
    use Types
    implicit none
    ! Variables    
    TYPE (tBase), TARGET :: Ext1(5)    
    CALL TBProblem(Ext1)
    end program TypeBoundProcedures[/plain]
0 Kudos
5 Replies
rogcar
Beginner
689 Views
Hello, Thomas

It may seen silly my answer, but youshould call your function directly, without using the pointer or class structure. But if you are trying toaccess a routine from another object, then it does work. Just create an object and call like you did. Then it will work.

Regards,
Roger

0 Kudos
Steven_L_Intel1
Employee
689 Views
I think this is a bug we've recently fixed for a future update - I'll check that on Monday.
0 Kudos
Steven_L_Intel1
Employee
689 Views
Apparently this is a different bug. Issue ID is DPD200142454.
0 Kudos
Steven_L_Intel1
Employee
689 Views
The issue from this thread has been fixed in our sources. The fix ought to appear in Update 5, planned for late January or early February.
0 Kudos
Steven_L_Intel1
Employee
689 Views
Actually, update 6, available now.
0 Kudos
Reply