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

Assigning variable of derived type - conformant code or not

johnyb_
New Contributor I
484 Views

With the following code 

module m_1
    implicit none

    type t_1
        integer i
    contains
        procedure, private :: t1_ass_i
        generic   :: assignment(=) => t1_ass_i
    end type

    contains

        elemental subroutine t1_ass_i( var, expr )
            class(t_1),       intent(out) :: var
            integer, intent(in)  :: expr
            var%i = expr
        end subroutine
end module

module m2
    use m_1
    implicit none

    type :: T_2
        LOGICAL :: a_flag
    end type
    
    type:: T_3
        type(t_1) :: a_date
    end type
    
    type :: T_4
    end type
    
    type, public::  T_5
        type(T_2) :: v_t2
        type(T_3) :: v_t3
        type(T_4) :: v_t4
    end type
end module

program test
    use m2
    implicit none

    type(T_5) :: a1, a2
    a1%v_t2%a_flag = .true.
    a2 = a1
    print *, a1%v_t2%a_flag
    print *, a2%v_t2%a_flag
end program test

the result I expect is:

T
T

but we get:

T
F

the fact that commenting the line 

        type(T_4) :: v_t4

leads to the expected result makes me think this is a compiler bug, but I am not 100% of my interpretation of the standard re components with defined assignment.

I am currently using ifort v17.0.4.210 Build 20170411

0 Kudos
1 Solution
johnyb_
New Contributor I
483 Views

Thank you Steve,

I have submitted a support request, may I say it is a painfully complicated and longwinded process.

 

View solution in original post

0 Kudos
2 Replies
Steve_Lionel
Honored Contributor III
484 Views

I agree with you that this appears to be a compiler bug. Please report it via the Intel Online Service Center.

The standard says, for intrinsic assignment of derived types:

An intrinsic assignment where the variable is of derived type is performed as if each component of the variable
were assigned from the corresponding component of expr using pointer assignment for each pointer
component, defined assignment for each nonpointer nonallocatable component of a type that has a type-bound
defined assignment consistent with the component, intrinsic assignment for each other nonpointer nonallocatable
component, and intrinsic assignment for each allocated coarray component

0 Kudos
johnyb_
New Contributor I
484 Views

Thank you Steve,

I have submitted a support request, may I say it is a painfully complicated and longwinded process.

 

0 Kudos
Reply