Problem with initialization of procedure pointer component in derived-type variables

Problem with initialization of procedure pointer component in derived-type variables

Bild des Benutzers flying_hermes

Hi,

I don't know if the following problem has already been reported since I found no mention of it in this forum.

The problem, which is either a bug or a unsupported feature, is related to initialization of procedure pointer component in derived-type variables.

Here's an example:

module Procedure_Pointer
  implicit none
  type :: PPC_Type
    real(8)                           ::      R1, R2
    procedure(PPC_Interface) ,pointer ::      PPC_1
    procedure(PPC_Interface) ,pointer ::      PPC_2 => null()
    procedure(PPC_Interface) ,pointer ::      PPC_3 => MyPPC    ! Buggy line !!!
  end type
  abstract interface
    real(8) Function PPC_Interface( This )
      import                      :: PPC_Type
      class(PPC_Type) ,intent(in) :: This
    end Function
  end interface
  contains
real(8) Function MyPPC( This )
  class(PPC_Type) ,intent(in) :: This
  MyPPC = This%R1 * This%R2
End Function
End Module
Program Test_PPC
  use Procedure_Pointer
  implicit none
  type(PPC_Type)  :: var
  write(*,*) 'Start'
  
  var%R1 = 2.0
  var%R2 = 3.0
  
  var%PPC_1 => MyPPC
  var%PPC_2 => MyPPC
  write(*,*) 'var%PPC_1=', var%PPC_1()
  write(*,*) 'var%PPC_2=', var%PPC_2()
  
  write(*,*) 'End'
  
End Program

This code gives me the following comilation error:

! ifort bug_porcedure_pointer.f90
! bug_porcedure_pointer.f90(13): error #6592: This symbol must be a defined parameter, an enumerator, or an argument of an inquiry function that evaluates to a compile-time constant.   [MYPPC]
!     procedure(PPC_Interface) ,pointer ::      PPC_3 => MyPPC    ! Buggy line !!!
! -------------------------------------------------------^
! bug_porcedure_pointer.f90(13): error #6973: This is not a valid initialization expression.   [MYPPC]
!     procedure(PPC_Interface) ,pointer ::      PPC_3 => MyPPC    ! Buggy line !!!
! -------------------------------------------------------^
! bug_porcedure_pointer.f90(25): error #6645: The name of the module procedure conflicts with a name in the encompassing scoping unit.   [MYPPC]
! real(8) Function MyPPC( This )
! -----------------^
! bug_porcedure_pointer.f90(13): error #6404: This name does not have a type, and must have an explicit type.   [MYPPC]
!     procedure(PPC_Interface) ,pointer ::      PPC_3 => MyPPC    ! Buggy line !!!
! -------------------------------------------------------^
! bug_porcedure_pointer.f90(46): error #6460: This is not a field name that is defined in the encompassing structure.   [PPC_3]
!   write(*,*) 'var%PPC_3=', var%PPC_3()
! -------------------------------^
! bug_porcedure_pointer.f90(46): error #6158: The structure-name is invalid or is missing.   [VAR]
!   write(*,*) 'var%PPC_3=', var%PPC_3()
! ---------------------------^
! compilation aborted for bug_porcedure_pointer.f90 (code 1)

The compilation error vanishes if the definition of the PPC_3 procedure pointer component is commented.

However, I belive that such an initialization is valid.

Am I right ?

Thanks

2 Beiträge / 0 neu
Letzter Beitrag
Nähere Informationen zur Compiler-Optimierung finden Sie in unserem Optimierungshinweis.
Bild des Benutzers Steve Lionel (Intel)

This is a F2008 feature not yet supported. In Intel Fortran, we support the Fortran 2003 ability to initialize pointers to NULL(). F2008 adds the ability to point to an "initial-data-target".

Steve

Melden Sie sich an, um einen Kommentar zu hinterlassen.