- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, the parameterized derived type implementation is still quite buggy, and flang is not even nearly a full F2003 compiler.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.)
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page