From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 8481C3844051; Thu, 3 Jun 2021 08:35:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8481C3844051 From: "federico.perini at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/59202] Erroneous argument aliasing with defined assignment Date: Thu, 03 Jun 2021 08:35:59 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: federico.perini at gmail dot com X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Jun 2021 08:35:59 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D59202 --- Comment #4 from federico --- 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 w= ith gfortran 10.2.0:=20 module assign implicit none private type, public :: t integer :: a=20=20=20=20=20=20=20=20=20=20=20=20=20=20 contains procedure :: destroy=3D>t_destroy procedure :: assign=3D>t_assign generic :: assignment(=3D) =3D>assign=20 end type t contains elemental subroutine t_destroy(this) class(t), intent(inout) :: this this%a =3D 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=3D>that) type is (t) this%a =3D thatPtr%a=20=20=20=20 end select end subroutine t_assign end module assign program test use assign type(t), allocatable :: t1(:) allocate(t1(10)) do i=3D1,10 t1(i)%a =3D i end do=20=20 n =3D 0 do i=3D1,10 if (mod(i,2)/=3D0) then=20 n =3D n + 1 t1(n) =3D t1(i) print *, 'i=3D',i,' t(i)%a=3D',t1(i)%a,' expected t(i)%a=3D',= i,': ',merge('ERROR!','OK ',t1(i)%a/=3Di) endif end do end program test=