Copy class into type bug ?

patnel97269-gfortran@yahoo.fr patnel97269-gfortran@yahoo.fr
Thu Oct 16 13:56:00 GMT 2014






Le Jeudi 16 octobre 2014 0h14, Tobias Burnus <burnus@net-b.de> a écrit :
patnel97269-gfortran@yahoo.fr wrote:



> I have a weird result when trying to copy a polymorphic class object into a type variable.

Confirmed. I have filled it as 
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63553 ; thanks for the report!

Seems as if the address of the virtual table gets assigned instead of 
the data of the class.

Tobias





Thank you Tobias,

I think another related bug (probably the same) is assigning the origin type as follow :

program toto
implicit none

type mother
integer :: i
end type mother
type,extends(mother) :: child
end type child

type(mother) :: tm
type(child) :: tc
class(mother),allocatable :: cm,cm2
class(child),allocatable :: cc

 allocate(cm)
 allocate(child::cm2)
 cm%i=10
 select type (cm2)
 type is (child)
                cm2%mother=cm
 end select
 print *,'class cm2 is type tm',extends_type_of(cm2,tm)
 print *,'class cm2 is class cm',extends_type_of(cm2,cm)
 print *,'class cm2 is type tc',extends_type_of(cm2,tc)
 print *,'class cm2 is class cc',extends_type_of(cm2,cc)
 print *,'cm2=cm', cm%i,cm2%i

end program

Also I'm not sure that "class cm2 is type tc" False is the right answer, ifort is reporting True .

Pat.



More information about the Fortran mailing list