Am 10.11.25 um 21:41 schrieb Harald Anlauf:
Hi Chris!


Hmm, this works for scalar instances, but does not get the bounds
right for arrays.

Example: add to test_self_assign of finalizer_self_assign.f90:

   block
     type(node_t), allocatable :: b(:), c(:)
     allocate (b(5:5))
     b = (b)
     print *, lbound (b)             ! Should print: 1
   end block

This now prints:

            5

Interestingly, NAG prints the same!
Only Intel (ifx) gets it right:

            1

This is because lbound (b,1) = 5, but lbound ((b),1) = 1;
see F2023:10.2.1.3 and the description of LBOUND.
(The parentheses enforce the resetting of the bounds).

Oops, I have to correct myself and put a brown bag over my head!

Because the lhs is already allocated and has the right shape,
no reallocation is done, and the bounds are correct.
So your patch is right and Intel is wrong.

More clearly:

  block
    type(node_t), allocatable :: b(:), c(:)
    allocate (b(5:5))
    c = (b)
    b = (b)
    print *, lbound (b)             ! Should print: 5
    print *, lbound (c)             ! Should print: 1
  end block

Confirmed by NAG.

So OK from my side.

Sorry for the confusion on my side.

Harald


@Jerry: we could proceed with the current patch, maybe add a TODO
for the array assignment case and let Chris check if he finds a
separate solution for the rank /= 0 version.

Thanks,
Harald

Thanks,
Harald



Best,
Chris



Reply via email to