with Ada.Text_IO; use Ada.Text_IO;
with Ada.Unchecked_Deallocation;
procedure Main is
   type Root is tagged record
      N : Integer := 0;
   end record;
   type Child is new Root with record
      M : Integer := 0;
   end record;
   type Acc is access Integer;
   procedure Free is new Ada.Unchecked_Deallocation (Integer, Acc);
   S : String (1 .. 10) := "abcdefghij";
   V : Child;
   --  a slice (RM 4.1.2): writes through it are writes of S, and it sees S's changes
   T : String renames S (3 .. 5);
   --  a view conversion (RM 4.6(5/2)) and a qualified expression (RM 4.7) of an object
   R : Root renames Root (V);
   L : Natural renames Natural'(V.N);
   A : Acc := new Integer'(1);
begin
   pragma Assert (T = "cde" and T'First = 3 and R.N = 0 and L = 0);
   T := "CDE";
   T (4) := '4';
   S (5) := '5';
   pragma Assert (S = "abC45fghij" and T = "C45");
   R.N := 3;
   pragma Assert (V.N = 3 and L = 3);
   --  what an access object designates: a borrower of the object while the renaming lives
   declare
      X : Integer renames A.all;
   begin
      X := X + 1;
   end;
   pragma Assert (A.all = 2);
   Put_Line (S & " " & T & Integer'Image (L) & Integer'Image (A.all));
   Free (A);
end Main;
