- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
the attached code should print "1 2", however, it prints "2 2".
Indeed, it seems that each assignment to V(I) in fact assigns to the
whole array V.
ifort -V
Intel(R) Fortran Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 13.1 Build 20130121
(I don't have the very latest version, so I don't know how it works).
program ts
implicit none
type, abstract :: at
integer :: f
end type at
type, extends(at) :: t
end type t
type :: tv
class(at), allocatable :: x
end type tv
type(tv), allocatable :: v(:)
type(tv) :: x
allocate(v(2))
allocate(t::x%x)
x%x%f = 1
v(1) = x
x%x%f = 2
v(2) = x
! Should print "1 2"
write(*,*) v(1)%x%f, v(2)%x%f
end program ts
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I can reproduce this with the latest version - thanks. We'll look into it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Escalated as issue DPD200243378. It is somewhat interesting that intrinsic assignment to a polymorphic variable is non-standard in F2003 (it is new in F2008) and we don't yet support that, but a polymorphic allocatable component of a derived type is ok in F2003 (and we are supposed to support that feature.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve, thank you for the update.
It is somewhat interesting that intrinsic assignment to a polymorphic variable is non-standard in F2003 (it is new in F2008) and we don't yet support that, but a polymorphic allocatable component of a derived type is ok in F2003 (and we are supposed to support that feature.)
Yes, indeed. It looks like this parallels what happened with allocatable arrays: initially they were reallocated only inside derived types (F95+TR), but not as standalone variables, and then this "inconsistency" was removed allowing reallocation of the left-hand-side (F2003).
Marco
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This has been fixed for a future update, probably October.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Interestingly, using the (hopefully not so old-fashioned) "Intel(R) Fortran Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 12.1.5.339 Build 20120612", the provided example compiles fine, nevertheless the result seems to be "0 0"...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The problem is not a compile error, it's wrong results at run-time. Version 12.1.5 is about a year old
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, of course, I just wanted to point out that the older version produces a different result (still incorrect, though). There, the problem seems to mainly consist in the fact that after the assignment:
[fortran]
v(1) = x
[/fortran]
v(1)%x is not allocated, although it (in F2003) should, right?
Using ifort 13, ALLOCATED(v(1)%x) returns .TRUE.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The present problem is that the compiler incorrectly handles the assignments to v(1) and v(2), effectively assigning to all elements of v for each assignment. The write of v(2) overwrote the value of v(1), leading to the wrong result.
I would not be astonished that 12.1 got it even more wrong.

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