- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello. I noticed this problem with an allocatable character variable when used inside a polymorphic linked list compiled with ifort version 13.0.1 . The output is the following.
First output: allocatable character
D
D
D
D
Second output: assigned length character
A
B
C
D
What am I doing wrong?
[fortran] program main
implicit none
type :: linked_list
class(linked_list), pointer :: prev
class(linked_list), pointer :: next
class(*), pointer :: data
end type
type :: named_type_A
character(:),allocatable :: name
end type
type :: named_type_B
character(len=1) :: name
end type
type(named_type_A),target :: t_a
type(named_type_B),target :: t_b
class(*),pointer :: polydata
class(linked_list),pointer :: listA, listB
character(len=1),dimension(4) :: ch
integer :: i_list
ch=(/'A', 'B', 'C ', 'D'/)
! FIRST OUTPUT CORRECT
print*, 'First output: allocatable character'
polydata=>t_a
allocate(listA)
do i_list = 1, 4
t_a%name=ch(i_list)
allocate(listA%data,source=polydata)
allocate(listA%next)
listA%next%prev=>listA
listA=>listA%next
end do
do while(associated(listA%prev))
listA=>listA%prev
end do
do i_list = 1, 4
select type(q=>listA%data)
type is(named_type_A)
print*, q%name
end select
listA=>listA%next
end do
print*, 'Second output: assigned length character'
polydata=>t_b
allocate(listb)
do i_list = 1, 4
t_b%name=ch(i_list)
allocate(listb%data,source=polydata)
allocate(listb%next)
listb%next%prev=>listb
listb=>listb%next
end do
do while(associated(listB%prev))
listB=>listB%prev
end do
do i_list = 1, 4
select type(q=>listB%data)
type is(named_type_B)
print*, q%name
end select
listB=>listB%next
end do
end program[/fortran]
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I don't think you are doing anything wrong, but I need to investigate further. My guess is that this is a compiler bug, I will let you know.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I can reproduce this, though the synmptoms vary depending on how and on which platform I build it. I have escalated the problem as issue DPD200240765. Thanks for the nice example.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
We have fixed this for a release later this year.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The developer who worked on this just sent me an additional note...
There is actually a fairly significant bug in this code. In both case 1 and case 2, the first list element never nullifies its prev field, and then relies on that field being NULL later on in the code:
[fortran]
do while(associated(listA%prev))
listA=>listA%prev
end do
[/fortran]
To fix this, after the line:
[fortran]
allocate(listA)
[/fortran]
there needs to be added the line:
[fortran]
nullify(listA%prev)
[/fortran]
and after the line:
[fortran]
allocate(listB)
[/fortran]
there needs to be added the line:
[fortran]
nullify(listB%prev)
[/fortran]
This is actually the cause of several of the manifestations of the problem reported in the original description.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry for this unwanted bug. But in the original code in which I first noticed this problem, the line 4 of the example actually was
[fortran]
class(linked_list), pointer :: prev=>null()
[/fortran]
Thanks,
Juan
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page