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

error #8339: dummy argument of a final subroutine cannot be...

Gustavo_B_1
Beginner
1,758 Views

Hello all.

Trying to learn how to do OOP with Fortran, and receiving " error #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]  " when trying to run a modified example of S.C.Chapman "Fortran 95/2003 for Scientists and Engineers" (3rd edition), about how to use finalizers (in page 790). I was trying to change the real vector class in that example by a character string class (same error with the real vector in the book), to add some methods afterwards, and to see if I was able to emulate the behavior of string classes in other languages. The book warns the code in the example might not work in the Fortran compilers available by that time. Code is attached. I am using Intel Compiler XE v14 SP1.

Any advice?

Thanks and regards.

   module class_string
   implicit none
   type, public :: string
      character, dimension(:), pointer :: text
      logical :: is_allocated = .false.
   contains
      final :: clean_text
   end type
   contains 
      subroutine clean_text(this)
         class(string) :: this
         integer :: istat
         if (this%is_allocated) then
            deallocate(this%text, stat=istat)
         end if
      end subroutine      
   end module
0 Kudos
7 Replies
Arjen_Markus
Honored Contributor II
1,758 Views

The message says that the dummy argument can not be (among others) polymorphic. Hence you cannot use the "class" keyword. You will have to use "type" instead and define a specific final subroutine for descendant classes, if the need arises. I have hardly used them myself so far. In this particular case you could do without it - replace the pointer to a character string by an allocatable and the deallocation now required will be automatic.

Regards,

Arjen

0 Kudos
Steven_L_Intel1
Employee
1,758 Views

The example in the book is wrong, which astonishes me somewhat because I know Chapman used the Intel compiler on the examples. I checked the original sample from the book and it gets the same error. This is not mentioned in the errata, though I see the errata has not been updated since 2007.

Curiously, the ZIP for the book's examples includes an alternate version of this sample with the argument to the FINAL routine declared with TYPE rather than CLASS, but the FINAL declaration itself is commented out. I will write Chapman about this and see what he says.

0 Kudos
Steven_L_Intel1
Employee
1,758 Views

The program violates F2003 constraint C473 (C480 in F2008) which says, “That argument shall be nonoptional and shall be a nonpointer, nonallocatable, nonpolymorphic variable of the derived type being defined.” 

0 Kudos
Gustavo_B_1
Beginner
1,758 Views

Hello Arjen and Steve. Thanks to both for the quick answer. Changing the code with class by type and pointer by allocatable makes it work. Regards.

0 Kudos
FortranFan
Honored Contributor III
1,758 Views

You may also want to review the books mentioned in Dr Fortran blog: https://software.intel.com/en-us/blogs/2013/12/30/doctor-fortran-in-its-a-modern-fortran-world which are more up-to-date with OOP features than the Chapman book.  In particular, take a look at the book in the footnote by Rouson et al. on Scientific Software Design: The Object-Oriented Way.

 

0 Kudos
Gustavo_B_1
Beginner
1,758 Views

Thanks. If I manage to get  copies of the books in that page I'll review  them. I understand, if mentioned herein, that the last one also deals with fortran specificities. Regards.

0 Kudos
Steven_L_Intel1
Employee
1,758 Views

Steve Chapman responded to me:

As it happens, the code examples shown were done before IVF implemented of the features, and I did them based on reading the standard!  By good fortune, I am starting a revision of the book this Autumn, and I will incorporate the fix then.

0 Kudos
Reply