Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
1 View

final routines in fortran 2003

Jump to solution

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

Accepted Solutions
Highlighted
Valued Contributor I
1 View

The Fortran Standard says in

Jump to solution

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
Highlighted
Valued Contributor I
2 Views

The Fortran Standard says in

Jump to solution

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
Highlighted
1 View

Thanks . Well it actually

Jump to solution

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
Highlighted
Valued Contributor I
1 View

Yes, the parameterized

Jump to solution

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

0 Kudos
Highlighted
Black Belt
1 View

Quote:Juergen R. wrote:

Jump to solution

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.)

Steve (aka "Doctor Fortran") - https://stevelionel.com/drfortran
0 Kudos