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

Defined assignment and allocatable components

Nick_M_3
New Contributor I
248 Views

My reading of both Fortran 2003 and Fortran 2008 (7.4.1.3, page 141) is that it should call my defined assignment for the explicit one between checkpoints Bravo and Charlie as well as for the one before Alpha.

MODULE Assign
    IMPLICIT NONE
    TYPE, PUBLIC :: Mytype
        INTEGER :: comp = 123
    CONTAINS
        PROCEDURE, PRIVATE :: Copy
        GENERIC :: ASSIGNMENT (=) => Copy
    END TYPE Mytype
CONTAINS
    SUBROUTINE Copy (a, b)
        CLASS(Mytype), INTENT(OUT) :: a
        CLASS(Mytype), INTENT(IN) :: b
        PRINT *, 'Copying', b%comp
        a%comp = b%comp
    END SUBROUTINE Copy
END MODULE Assign

PROGRAM Main
    USE Assign
    IMPLICIT NONE
    TYPE :: Weeble
        TYPE(Mytype), ALLOCATABLE :: arr
    END TYPE Weeble
    TYPE(Mytype) :: this, that
    TYPE(Weeble) :: object, temp

    that%comp = 456
    this = that
    PRINT *, 'Checkpoint Alpha'
    call Cheque(this)
    PRINT *, 'Checkpoint Bravo'
    ALLOCATE(object%arr)
    object%arr%comp = 123
    temp = object
    PRINT *, 'Checking', object%arr%comp
    PRINT *, 'Checkpoint Charlie'
    CALL Check(temp)
CONTAINS
    SUBROUTINE Cheque (arg)
        TYPE(Mytype), VALUE :: arg
        PRINT *, 'Checking', arg%comp
    END SUBROUTINE Cheque
    SUBROUTINE Check (arg)
        TYPE(Weeble), VALUE :: arg
        PRINT *, 'Checking', arg%arr%comp
    END SUBROUTINE Check
END PROGRAM Main

 

0 Kudos
2 Replies
Steven_L_Intel1
Employee
248 Views

Hi, Nick. I agree with you that the defined assignment should be used in this case. I have escalated the problem as issue DPD200358909 and will let you know here of any progress.

0 Kudos
Steven_L_Intel1
Employee
248 Views

We have fixed this and I expect the fix to appear in Update 2. The error is triggered when there is a scalar, allocatable component with a defined assignment - sometimes the compiler won't use the defined assignment in that case.

0 Kudos
Reply