public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug ada/94181] New: Misidentified dangling reference in container implementation
@ 2020-03-15 16:04 simon at pushface dot org
  2022-02-28 14:37 ` [Bug ada/94181] " simon at pushface dot org
  2022-03-24 10:12 ` ebotcazou at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: simon at pushface dot org @ 2020-03-15 16:04 UTC (permalink / raw)
  To: gcc-bugs

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug ada/94181] Misidentified dangling reference in container implementation
  2020-03-15 16:04 [Bug ada/94181] New: Misidentified dangling reference in container implementation simon at pushface dot org
@ 2022-02-28 14:37 ` simon at pushface dot org
  2022-03-24 10:12 ` ebotcazou at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: simon at pushface dot org @ 2022-02-28 14:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94181

--- Comment #1 from simon at pushface dot org ---
Fixed in 10.1.0 (also OK in 11.2.0, 12.0.1)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug ada/94181] Misidentified dangling reference in container implementation
  2020-03-15 16:04 [Bug ada/94181] New: Misidentified dangling reference in container implementation simon at pushface dot org
  2022-02-28 14:37 ` [Bug ada/94181] " simon at pushface dot org
@ 2022-03-24 10:12 ` ebotcazou at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: ebotcazou at gcc dot gnu.org @ 2022-03-24 10:12 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94181

Eric Botcazou <ebotcazou at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
   Target Milestone|---                         |10.2
                 CC|                            |ebotcazou at gcc dot gnu.org
         Resolution|---                         |FIXED

--- Comment #2 from Eric Botcazou <ebotcazou at gcc dot gnu.org> ---
Thanks for checking.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-03-24 10:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-15 16:04 [Bug ada/94181] New: Misidentified dangling reference in container implementation simon at pushface dot org
2022-02-28 14:37 ` [Bug ada/94181] " simon at pushface dot org
2022-03-24 10:12 ` ebotcazou at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).