[Bug fortran/59202] Erroneous argument aliasing with defined assignment
federico.perini at gmail dot com
gcc-bugzilla@gcc.gnu.org
Thu Jun 3 08:35:59 GMT 2021
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59202
--- Comment #4 from federico <federico.perini at gmail dot com> ---
The self-assignment issue is present even if the derived type has no
allocatable components. Here is a sample test program that gives an error with
gfortran 10.2.0:
module assign
implicit none
private
type, public :: t
integer :: a
contains
procedure :: destroy=>t_destroy
procedure :: assign=>t_assign
generic :: assignment(=) =>assign
end type t
contains
elemental subroutine t_destroy(this)
class(t), intent(inout) :: this
this%a = 0
end subroutine t_destroy
subroutine t_assign(this,that)
class(t), intent(inout) :: this
class(t), intent(in) :: that
call this%destroy() ! Clean memory first
select type (thatPtr=>that)
type is (t)
this%a = thatPtr%a
end select
end subroutine t_assign
end module assign
program test
use assign
type(t), allocatable :: t1(:)
allocate(t1(10))
do i=1,10
t1(i)%a = i
end do
n = 0
do i=1,10
if (mod(i,2)/=0) then
n = n + 1
t1(n) = t1(i)
print *, 'i=',i,' t(i)%a=',t1(i)%a,' expected t(i)%a=',i,':
',merge('ERROR!','OK ',t1(i)%a/=i)
endif
end do
end program test
More information about the Gcc-bugs
mailing list