Defined assignment and allocatable components

Defined assignment and allocatable components

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

 

3 post / 0 nuovi
Ultimo contenuto
Per informazioni complete sulle ottimizzazioni del compilatore, consultare l'Avviso sull'ottimizzazione

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.

Steve

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.

Steve

Accedere per lasciare un commento.