[J3] Self-assignment of allocatable component
Malcolm Cohen
malcolm at nag-j.co.jp
Fri Jul 30 08:52:02 UTC 2021
Hi Vipul,
Thanks for your example program. It certainly looks valid to me.
I am embarrassed to have to admit that the NAG compiler gets this wrong when the assignment avoids the round-trip to the memory allocator (we do this when the allocated types/sizes/etc are the same). In that case we forgot to invoke the final subroutine.
I have now fixed this, so that we produce the output you expect. The fix will be in build 7055.
Cheers,
--
..............Malcolm Cohen, NAG Oxford/Tokyo.
From: J3 <j3-bounces at mailman.j3-fortran.org> On Behalf Of Vipul Parekh via J3
Sent: Wednesday, July 28, 2021 10:54 PM
To: General J3 interest list <j3 at mailman.j3-fortran.org>
Cc: Vipul Parekh <parekhvs at gmail.com>
Subject: Re: [J3] Self-assignment of allocatable component
On Wed, Jul 28, 2021 at 9:01 AM Daniel C Chen via J3 <j3 at mailman.j3-fortran.org <mailto:j3 at mailman.j3-fortran.org> > wrote:
Thanks Malcolm and all for the clarification.
..
From: "Malcolm Cohen via J3" <j3 at mailman.j3-fortran.org <mailto:j3 at mailman.j3-fortran.org> >
To: "'General J3 interest list'" <j3 at mailman.j3-fortran.org <mailto:j3 at mailman.j3-fortran.org> >..
Hi Daniel,
Yes, you are quite right, so in that case, X=X would involve at least
1. Capturing the value of X%I,
2. Finalising X%I,
3. Restoring the value of X%I. ..
Hi Daniel and Malcolm,
Interesting discussion. If I understood the clarification thus far correctly, the following program seems to me to conform - would you agree?
module m
type :: t
character(len=10) :: objname = ""
integer :: dat = 0
contains
final :: finalize_t
end type
type, extends(t) :: u
end type
contains
impure elemental subroutine finalize_t( this )
type(t), intent(inout) :: this
print *, "t::finalize_t invoked for ", this%objname
end subroutine
end module
module n
use m
type :: v
class(t), allocatable :: i
end type
contains
subroutine sub()
type(v) :: x, y
allocate( t :: x%i ) ; x%i%objname = "x%i" ; x%i%dat = 42
allocate( u :: y%i ) ; y%i%objname = "y%i"
if ( allocated(y%i) ) then
print *, "Initially, y%i%dat = ", y%i%dat, "; expected is 0"
end if
y = x ; y%i%objname = "y%i"
if ( allocated(y%i) ) then
print *, "y%i%dat = ", y%i%dat, "; expected is 42"
end if
end subroutine
end module
use n
call sub()
end
And the program output per the standard might be as follows - note the order of the last 2 lines in the output can be ignored:
Initially, y%i%dat = 0 ; expected is 0
t::finalize_t invoked for y%i
y%i%dat = 42 ; expected is 42
t::finalize_t invoked for y%i
t::finalize_t invoked for x%i
However only one out of several processors I tried gave the above output. There is variance among the rest when it comes to output from the (impure) finalizer. Is the expected output I list above conformant, or is that the other processors are yet to conform to the standard when it comes to finalization?
Daniel, is it possible for you to check the IBM processor with this example and provide your feedback and comments?
Thanks,
Vipul
Disclaimer
The Numerical Algorithms Group Ltd is a company registered in England and Wales with company number 1249803. The registered office is: 30 St. Giles, Oxford, OX1 3LE, United Kingdom. Please see our Privacy Notice <https://www.nag.co.uk/content/privacy-notice> for information on how we process personal data and for details of how to stop or limit communications from us.
This e-mail has been scanned for all viruses and malware, and may have been automatically archived by Mimecast Ltd, an innovator in Software as a Service (SaaS) for business.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20210730/eb28b23e/attachment-0001.htm>
More information about the J3
mailing list