https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94181
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=48035&action=edit Reproducer This arose in a simple implementation of a Container’s Reference function: type Reference_Type (Element : not null access Element_Type) is record Dummy : Integer := raise Program_Error with "uninitialized reference"; end record; function Reference (C : aliased in out Container; Position : in Cursor) return Reference_Type is pragma Unreferenced (C); begin return (Element => Position.The_Node.all.The_Element'Access, Dummy => 1); end Reference; With GCC 9, this was fine (so long as that .all is in there! Weird). With GCC 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 => Position.The_Node.all.The_Element'Access, Dummy => 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 := (Element => Position.The_Node.The_Element'Unchecked_Access, Dummy => 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