Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!
26754 Discussions

Compiler error allocating a member variable of a recursive derived type with source or mold

Victor_S_2
Beginner
98 Views

Deal Intel Fortran Compiler Support team,

I'm getting a compiler error while allocating with mold a member variable of a recursive derived type. Is this legal or I'm committing some mistake?

The error message I get is the following one:

ifort-test.f90(30): error #8152: Neither the ERRMSG= variable nor any part of the source expression in SOURCE= or MOLD= specifiers may be allocated in the ALLOCATE statement in which it appears.   [MY_OBJECT]
        allocate(this%next_level%my_object, mold=this%my_object, stat=error)
------------------------------------------------------^

I can reproduce this with the code snippet below.

Thanks in advance,

Víctor.

 

module my_module

implicit none
private

    type :: object_t
    end type

    type, extends(object_t) :: object1_t
    end type

    type, extends(object_t) :: object2_t
    end type

    type :: level_t
    private
        class(object_t), allocatable :: my_object
        type(level_t), pointer :: next_level
    contains
    private
        procedure :: allocate_next_level
    end type

contains

    subroutine allocate_next_level(this)
        class(level_t), intent(inout) :: this
        integer                       :: error
        allocate(this%next_level, stat=error)
        allocate(this%next_level%my_object, mold=this%my_object, stat=error) ! <- error occurs in this line
    end subroutine

end module my_module

0 Kudos
1 Reply
Steven_L_Intel1
Employee
98 Views

Thanks - this is very similar to a problem we fixed a few years ago, but not quite the same. Escalated as issue DPD200415804.

Reply