Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29285 Discussions

INTENT(OUT) in type-bound procedures

John4
Valued Contributor I
642 Views

When I run the code below (compiled with ifort 11.1 Update 4), I get 400 printed three times. Is it a bug, or is the compiler right at ignoring the initialization for a polymorphic argument?

!------------------------------------------------------------------------------
module mod1

implicit none
private
save

type, public :: t1
integer :: item = 300
contains
procedure :: destroy
end type

contains
subroutine destroy(this)
class(t1), intent(OUT) :: this
print *, this%item
end subroutine

end module mod1

program test

use mod1

implicit none

type(t1) :: a

continue

a%item = 400

print *, a%item

call a%destroy()

print *, a%item

end program test
!------------------------------------------------------------------------------

0 Kudos
5 Replies
IDZ_A_Intel
Employee
642 Views
That's a good question. Off the top of my head, I'd call this a compiler bug but I need to research it some more. If "this" were declared type(t1), then item should definitely be reset to 300 on entry to destroy, but I'm unsure about the effect of it being polymorphic. Stay tuned.
0 Kudos
abhimodak
New Contributor I
642 Views

Hi

While Steve comes back with the authoritative answer, I looked through the F2003 handbook (by Adams et al) and 95/2003 book by Metcalf et al to see if there are any exceptions to the Intent(OUT) when the object is polymorphic. But I did not find any. It would be a surprise if there was.

On the other hand: On page 238, chapter 7, of the handbook by Adams a special note is made about vector v (which is a polymorphic argument) being deallocated on entry because it is intent(out). Thus, this is a compiler bug.

Unfortunately, since update 4 messes up the debugger, it is not possible to step into the type-bound procedure and see the value of the variable to look/verify the behavior of intent(OUT).

Abhi

p.s. for whatever it is worth, running this snippet with IBM XLF v11 gives: 400, 300, 300 which is the correct answer.

0 Kudos
IDZ_A_Intel
Employee
642 Views
Reported to development as issue DPD200150651. I believe that CLASS(*) should also work here (it doesn't at present.)
0 Kudos
IDZ_A_Intel
Employee
642 Views
This has proven to be a complex issue that required inventing new mechanisms in the compiler and run-time library. We have done this for a future release.
0 Kudos
Steven_L_Intel1
Employee
642 Views

This was fixed in 13.0.

0 Kudos
Reply