From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D591A38A1031; Sun, 15 Mar 2020 16:04:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D591A38A1031 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1584288270; bh=KiOl0uB/ZnsBIBBdLp6F12w+A1wKGc0/qsg7AafZX9Y=; h=From:To:Subject:Date:From; b=SFC3Z5WgxpKaAsTUGUTMSdM7y1WEX6ZC7vYbKKrY4qkSt08y/5w0P1S8/A89lsL46 ZDlI2C4YjRyGJFqLIWZTiFx50a2tlpUiIClDqwMZ3o/VVi36uQXAVbZwRTTAYXQbq0 dbMWJZhLdnjd6tBSgTpdHpsNidSz32NsOeBGDvZE= From: "simon at pushface dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug ada/94181] New: Misidentified dangling reference in container implementation Date: Sun, 15 Mar 2020 16:04:29 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: ada X-Bugzilla-Version: 10.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: simon at pushface dot org X-Bugzilla-Status: UNCONFIRMED 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: 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: Sun, 15 Mar 2020 16:04:30 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D94181 Bug ID: 94181 Summary: Misidentified dangling reference in container implementation Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: ada Assignee: unassigned at gcc dot gnu.org Reporter: simon at pushface dot org Target Milestone: --- Created attachment 48035 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D48035&action=3Dedit Reproducer This arose in a simple implementation of a Container=E2=80=99s Reference fu= nction: type Reference_Type (Element : not null access Element_Type) is record Dummy : Integer :=3D raise Program_Error with "uninitialized refer= ence"; end record; function Reference (C : aliased in out Container; Position : in Cursor) return Reference_Type is pragma Unreferenced (C); begin return (Element =3D> Position.The_Node.all.The_Element'Access, Dummy = =3D> 1); end Reference; With GCC 9, this was fine (so long as that .all is in there! Weird). With G= CC 10.0.1 20200206 (experimental) (GCC), we get 3. function Reference 4. (C : aliased in out Container; Position : in Cursor) 5. return Reference_Type 6. is 7. pragma Unreferenced (C); 8. begin 9. return (Element =3D> Position.The_Node.all.The_Element'Access, Dummy =3D> 1); | >>> access discriminant in return aggregate would be a dangling reference 10. end Reference; This (the same style as used in Ada.Containers) is OK. function Reference_With_Extended_Return (C : aliased in out Container; Position : in Cursor) return Reference_Type is pragma Unreferenced (C); begin return R : constant Reference_Type :=3D (Element =3D> Position.The_Node.The_Element'Unchecked_Access, Dummy= =3D> 1) do null; end return; end Reference_With_Extended_Return; Randy Brukardt[1] thinks there should be no difference. [1] https://groups.google.com/d/msg/comp.lang.ada/IUQ6DUe3Shw/wULgGGjqAgAJ=