- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
[fortran]
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
[/fortran]
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page