Assignment with polymorphic component, wrong result

Assignment with polymorphic component, wrong result

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

9 post / 0 nuovi
Ultimo contenuto
Per informazioni complete sulle ottimizzazioni del compilatore, consultare l'Avviso sull'ottimizzazione
Ritratto di Steve Lionel (Intel)

I can reproduce this with the latest version - thanks. We'll look into it.

Steve
Ritratto di Steve Lionel (Intel)

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.)

Steve

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

Ritratto di Steve Lionel (Intel)

This has been fixed for a future update, probably October.

Steve

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"...

M.
Ritratto di Steve Lionel (Intel)

The problem is not a compile error, it's wrong results at run-time. Version 12.1.5 is about a year old

Steve

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:

v(1) = x

v(1)%x is not allocated, although it (in F2003) should, right?
Using ifort 13, ALLOCATED(v(1)%x) returns .TRUE.

M.
Ritratto di Steve Lionel (Intel)

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.

Steve

Accedere per lasciare un commento.