Dear all,
I would like to know if anyone knows
- How should we handle the assignment of a derived type variable to itself when the assignment operator for the derived type is overloaded in a subroutine?
- How is such a situation mentioned in the Fortran Standard?
Such a situation arises when extending stdlib_sorting
to support sorting arrays of bitset_large
type. The procedure assign_large
overloading assignment operator for the bitset_large
type is as follows:
pure module subroutine assign_large( set1, set2 )
! Used to define assignment for bitset_large
type(bitset_large), intent(out) :: set1
type(bitset_large), intent(in) :: set2
set1 % num_bits = set2 % num_bits
allocate( set1 % blocks( size( set2 % blocks, kind=bits_kind ) ) )
set1 % blocks(:) = set2 % blocks(:)
end subroutine assign_large
and when the same array element is put on both sides of the assignment operator, an error occurs with the message Fortran runtime error: Allocatable argument 'set2' is not allocated
. Here, the stdlib is built with gfortran 11.2.0 on Windows 11 and set2
is defined as the variable on the right-hand side of the assignment operator. The error may be due to the deallocation of the component blocks
of set2
caused by the intent(out)
attribute for set1
since set1
and set2
are the same variable.
I am trying to resolve this problem by removing assign_large
and using Fortran’s intrinsic assignment operation.
For more details, please see the issue #726 and pull-requests #723 and #727.
Thank you.