Problem with default assignment operator of type with polymorphic allocatable

Problem with default assignment operator of type with polymorphic allocatable

Hello, 

please take a look at this small program. MyIntType is not assigned properly in function MyIntWrapperGet (program prints error). Even stack is corrupted after calling MyIntWrapperGet. If you uncomment MyIntTypeAssignOperator, then everything works as expected, MyIntType is assigned properly, stack is not corrupted.

As for me, this code looks fine. So could you please explain if it is a bug in compiler or the code actually is wrong?

module MyMod
 type :: BaseExtraProps
 character(len=1) :: dummyChar
 end type BaseExtraProps
type :: MyIntType
 integer :: int
 class(BaseExtraProps), allocatable :: extra
 contains
 !procedure MyIntTypeAssignOperator
 !generic :: assignment(=) => MyIntTypeAssignOperator
 end type MyIntType
 type :: MyIntWrapperType
 type(MyIntType) :: myInt
 contains
 procedure :: Init => MyIntWrapperInit
 procedure :: Get => MyIntWrapperGet
 end type MyIntWrapperType
contains
 subroutine MyIntWrapperInit(this, int)
 class(MyIntWrapperType), intent(out) :: this
 integer, intent(in) :: int
this%myInt%int = int
 end subroutine MyIntWrapperInit
 function MyIntWrapperGet(this) result(val)
 class(MyIntWrapperType), intent(in) :: this
 type(MyIntType) :: val
 val = this%myInt
 end function MyIntWrapperGet
 !subroutine MyIntTypeAssignOperator(lhs, rhs)
 ! class(MyIntType), intent(inout) :: lhs
 ! type(MyIntType), intent(in) :: rhs
 ! 
 ! lhs%int = rhs%int
 ! allocate(lhs%extra, source=rhs%extra)
 !end subroutine MyIntTypeAssignOperator
end module MyMod
program AllocatableBug
 use MyMod
 implicit none
 type(MyIntWrapperType) :: myIntWrapper
 type(MyIntType) :: myInt
 integer :: i = 5
 call myIntWrapper%Init(i)
 myInt = myIntWrapper%Get()
 if (myIntWrapper%myInt%int /= myInt%int) then
 print *, 'error'
 else
 print *, 'ok'
 end if
end program AllocatableBug

3 posts / 0 nouveau(x)
Dernière contribution
Reportez-vous à notre Notice d'optimisation pour plus d'informations sur les choix et l'optimisation des performances dans les produits logiciels Intel.

By the way, I use Intel Visual Fortran Composer XE 2013.
 Also, if I change
class(BaseExtraProps), allocatable :: extra
to
type(BaseExtraProps), allocatable :: extra
I will get expected behavior and no erros, but in this case I want extra to be polymorphic.  

I can reproduce this in Update 2 but not in Update 3, which should be out this week. It looks similar to an issue I escalated a while ago.

Steve - Intel Developer Support

Laisser un commentaire

Veuillez ouvrir une session pour ajouter un commentaire. Pas encore membre ? Rejoignez-nous dès aujourd’hui