[J3] Self-assignment of allocatable component
Vipul Parekh
parekhvs at gmail.com
Wed Jul 28 13:54:23 UTC 2021
On Wed, Jul 28, 2021 at 9:01 AM Daniel C Chen via J3 <
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>
> To: "'General J3 interest list'" <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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20210728/5cc1bf6c/attachment.htm>
More information about the J3
mailing list