Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
2 Views

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

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
Highlighted
2 Views

Thanks - this is very similar

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

Retired 12/31/2016
0 Kudos