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

final routines in fortran 2003

Hafsia__Aouididi
Beginner
1,729 Views

I am testing the finalization of a derived type parameterized and i got errors when calling final .

This is the code :
 

module tests  
implicit none
  private
  public :: mytab
  type  mytab(n)
    integer, len :: n
    integer :: tab1(n)
contains
    final :: delete_mytab

#ifdef __GNUC__
      procedure :: delete => delete_mytab_gfortran
#endif    
    end type mytab

   interface mytab
      procedure create_mytab
    end interface mytab

  contains
    !Constructor
    function create_mytab(n)
      type(mytab(:)),allocatable :: create_mytab
      integer, intent(in) :: n
      allocate(mytab(n) :: create_mytab)
    end function

    !Destructor
    !nothing to do in this example
    subroutine delete_mytab(this)
      type(mytab(:)),allocatable :: this   
    end subroutine
#ifdef __GNUC__
    subroutine delete_mytab_gfortran(this)
      class(mytab(*)) :: this
      ..
    end subroutine
#endif
end module tests

 

and this is what i get when compiling whith ifort 18.0

rror #8339: The dummy argument of a final subroutine must be a variable of the derived type being defined and cannot be optional, pointer, allocatable, or polymorphic.   [THIS]
    subroutine delete_mytab(this)
----------------------------^
 error #8738: All length type parameters of the dummy argument must be assumed for a final subroutine.   [THIS]
    subroutine delete_mytab(this)

 

And when i call the derived type without the allocatable this is what i get :

 

#8730: A colon may only be used as a type parameter value in the declaration of an object that has the POINTER or ALLOCATABLE attribute.   [THIS]
      type(mytab(:)) :: this   

0 Kudos
1 Solution
Juergen_R_R
Valued Contributor II
1,729 Views

The Fortran Standard says in 7.5.6.1, C787:

A final-subroutine-name shall be the name of a module procedure with exactly one dummy argument. That argument shall be nonoptional and shall be a noncoarray, nonpointer, nonallocatable, nonpolymorphic variable of the derived type being defined. All length type parameters of the dummy argument shall be assumed. The dummy argument shall not have the INTENT (OUT) or VALUE attribute.

Look in Sec. 7.2 of the standard where type parameters are introduced. 7.2.4, C702 says:

A colon shall not be used as a type-param-value except in the declaration of an entity that has the POINTER or ALLOCATABLE attribute.

In 7.2.7, we have

An asterisk as a type-param-value specifies that a length type parameter is an assumed type parameter.

So this works:

  subroutine delete_mytab(this)
    type(mytab(*)) :: this
  end subroutine delete_mytab

 

View solution in original post

0 Kudos
4 Replies
Juergen_R_R
Valued Contributor II
1,730 Views

The Fortran Standard says in 7.5.6.1, C787:

A final-subroutine-name shall be the name of a module procedure with exactly one dummy argument. That argument shall be nonoptional and shall be a noncoarray, nonpointer, nonallocatable, nonpolymorphic variable of the derived type being defined. All length type parameters of the dummy argument shall be assumed. The dummy argument shall not have the INTENT (OUT) or VALUE attribute.

Look in Sec. 7.2 of the standard where type parameters are introduced. 7.2.4, C702 says:

A colon shall not be used as a type-param-value except in the declaration of an entity that has the POINTER or ALLOCATABLE attribute.

In 7.2.7, we have

An asterisk as a type-param-value specifies that a length type parameter is an assumed type parameter.

So this works:

  subroutine delete_mytab(this)
    type(mytab(*)) :: this
  end subroutine delete_mytab

 

0 Kudos
Hafsia__Aouididi
Beginner
1,729 Views

Thanks . Well it actually works now .

i still have another problem it doesn’t work neither with gfortran nor with flang.

I  ll try to fix this :) 

0 Kudos
Juergen_R_R
Valued Contributor II
1,729 Views

Yes, the parameterized derived type implementation is still quite buggy, and flang is not even nearly a full F2003 compiler.

0 Kudos
Steve_Lionel
Honored Contributor III
1,729 Views

Juergen R. wrote:

Yes, the parameterized derived type implementation is still quite buggy, and flang is not even nearly a full F2003 compiler.

Neither is gfortran (well, it's a lot closer at least.)

0 Kudos
Reply