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

Initialize derived type as parameter

Olsen__Oystein
Beginner
426 Views
Initializing a derived type as parameter fails if there is an assignment operator. This happens with latest FORTRAN compiler on openSUSE 11.4. The following code demonstrates the problem:
[fortran]MODULE DType
  IMPLICIT NONE
  PUBLIC

  INTEGER, PARAMETER :: I4B = SELECTED_INT_KIND(9)
  !INTEGER, PARAMETER  :: QP = SELECTED_REAL_KIND(6,37)
  !INTEGER, PARAMETER  :: QP = SELECTED_REAL_KIND(15,307)
  INTEGER, PARAMETER  :: QP = SELECTED_REAL_KIND(32,4931)

  TYPE JD
     INTEGER(I4B) :: JDN = 2451545
     REAL(QP)     :: FD = 0.0_QP
   CONTAINS
     GENERIC                  :: ASSIGNMENT(=) => setJD
     PROCEDURE, PRIVATE, PASS :: setJD
  END TYPE JD
CONTAINS
  SUBROUTINE setJD(a, b)
    CLASS(JD), INTENT(INOUT) :: a
    TYPE(JD), INTENT(IN)     :: b
    
    a%JDN = b%JDN
    a%FD = b%FD 
  END SUBROUTINE setJD
END MODULE DType

PROGRAM test_dtype
  USE DType
  IMPLICIT NONE
  
  TYPE(JD), PARAMETER :: testa = JD(2451546, 0.5_QP)
  TYPE(JD) :: testb = JD(2451546, 0.5_QP)

  WRITE(*,*) testa%JDN, testa%FD
  WRITE(*,*) testb%JDN, testb%FD
END PROGRAM test_dtype[/fortran]
The first write statement returns
1 1.0000000
instead of
2451546 0.50000000
0 Kudos
2 Replies
Steven_L_Intel1
Employee
426 Views
Thanks for the nice test case. I can reproduce the problem and verified that it is the presence of the type-bound operator that makes the difference, even though that operator is not used. I have escalated this as issue DPD200170709 and will let you know of any progress.
0 Kudos
Steven_L_Intel1
Employee
426 Views
This is fixed for a release later this year.
0 Kudos
Reply