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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ebotcazou at gcc dot gnu.org
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #2 from Eric Botcazou <ebotcazou at gcc dot gnu.org> ---
I think that your program is equivalent to:

with Ada.Text_IO; use Ada.Text_IO;
with Ada.Unchecked_Deallocation;

procedure Q is

   type Rec is record
      X : aliased Integer;
   end record;

   type Rec_Access is access all Rec;

   procedure Free is new Ada.Unchecked_Deallocation (Rec, Rec_Access);

   type Integer_Access is access all Integer;

   O : Rec_Access := new Rec'(X => 1);

   A : Integer_Access := O.X'Access;

begin
   Put_Line (A.all'Image);
   Free (O);
   Put_Line (A.all'Image);
end;

which is perfectly legal and nevertheless has a use-after-free.  That being
said, accessibility rules are arcane and their exegesis requires a significant
background.  GCC's bugzilla is not the appropriate place to discuss them,
please go to https://forum.ada-lang.io instead.

Reply via email to