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

Using polymorphism with TBPs in fortran 2003

Ned
Beginner
2,626 Views
Hi,

I am trying out ifort 11.1 on x86_64. When I tried to use some fortran 2003 features, namely polymorphic pointer / objects, extended types and TBPs, I ran into a lot of problems. (I put it in product defect, but not sure if it actually is a bug).

I have one base type and 2 extended types, both an extension of the base type.:

=========base_type.f03=========
module base
type:: base_type
contains
procedure :: pro_foo => base_pro_foo
end type base_type

contains
function base_pro_foo (this,str1)
class(base_type) :: this
character :: str1*(*)
...
end function base_pro_foo
..
end module base
=======extended_type1.f03========
module extension1
type, extends (base_type):: extended_type1
contains
procedure :: pro_foo => extend1_pro_foo ! override base_type procedure
end type extended_type1

function extend1_pro_foo (this,str1)
class(extended_type1) :: this
character :: str1*(*)
...
end function extend1_pro_foo
..
end module extension1

=======extended_type2.f03========
module extension2
type, extends(base_type) :: extended_type2
contains
procedure :: pro_foo => extend2_pro_foo ! override base_type procedure
end type extended_type2
.. [similar to extension 1]
end module extension2
================================

I compiled all the modules and built one static library file libmods.a.

Then, in my main program, I had:

============main.f03=============
use base
use extension1
use extension2

class(base_type), pointer :: myPointer
class(base_type), allocatable :: myObject
allocate(extension_type1 :: myObject)
! this doesn't work either: type(extension_type1) :: myObject
..
[some initialization of the object]
..
myPointer => myObject

myPointer% pro_foo('string_bar')

============================================================

When I compiled the code, I got this error:
--------------------------------------------------
ifort main.o -L/my_library_dir -lmods -lstdc++ -Imodule_source_directory \
-o mainBin

my_library_dir/libmods.a(extended_type1.o):(.rodata+0x0): multiple definition of `DYNTYPE_PACK_0.0.2'
my_library_dir/libmods.a(extended_type2.o):(.rodata+0x0): first defined here
my_library_dir/libmods.a(extended_type1.o):(.rodata+0x10): multiple definition of `DYNTYPE_PACK_1.0.2'
my_library_dir/libmods.a(extended_type2.o):(.rodata+0x10): first defined here
my_library_dir/libmods.a(extended_type1.o):(.rodata+0x20): multiple definition of `TBPLIST_PACK_0.0.2'
my_library_dir/libmods.a(extended_type2.o):(.rodata+0x20): first defined here
make[2]: *** [tempInput] Error 1
make[2]: Leaving directory `my_src_dir'
make[1]: *** [default] Error 2
make[1]: Leaving directory `my_src_dir'
make: *** [default] Error 1
=============================================================

"select type" resolution did not seem to help either. Does anyone know what the problem is?

Thank very much in advance!!

Best regards,
Ned
0 Kudos
21 Replies
Kevin_D_Intel
Employee
264 Views

Updates on internal tracking ids.

DPD200139983 - (memory leak) - Development reports there is no memory leak and the required de-allocations I noted are expected. In regard to the specific interest about deallocate (this%type2Ptr), this deallocates the specific field type2Ptr only. They added that deallocating a record (thisType1) should never deallocate
pointer fields within the record. That this is just part of the Fortran language.

DPD200139975 - (internal error in main.f90) - This is fixed the upcoming 11.1 Update 3 scheduled for later this month.

DPD200139961 - (internal error in type1_type.f90) - Fix is being targeted to the 11.1 update *after* Update 3. I will update this post when I know.


The last remaining defect DPD200139961 is fixed in the Intel Fortran Compiler Professional Edition 11.1 Update 4 (11.1.064 - Linux).
0 Kudos
Reply