comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey R. Carter" <spam.jrcarter.not@acm.nospam.org>
Subject: Re: Allocators and exceptions
Date: Wed, 12 Sep 2007 00:34:03 GMT
Date: 2007-09-12T00:34:03+00:00	[thread overview]
Message-ID: <%tGFi.80362$Xa3.20645@attbi_s22> (raw)
In-Reply-To: <1189547814.740732.220140@x40g2000prg.googlegroups.com>

Adam Beneschan wrote:
> 
> OK, I think I have one.  GNAT compiles and runs it, although I haven't
> checked the language rules carefully to make sure it's legal.

It looks legal to me. I've added a little test to see what's happening 
with P:

package Pak1 is
    type Rec1 is limited private;
    type Rec1_Acc is access all Rec1;

    function Func1 (R : Rec1_Acc) return Integer;

    procedure Check_P;
private
    type Rec1 is limited record
       F1 : Integer := 123;
       F2 : Integer := Func1 (Rec1'Unchecked_Access);
    end record;
end Pak1;

with Ada.Text_IO;

package body Pak1 is
    P : Rec1_Acc;

    function Func1 (R : Rec1_Acc) return Integer is
    begin
       P := R;
       if R.F1 > 100 then
          raise Constraint_Error;
       end if;
       return 1;
    end Func1;

    procedure Check_P is
       -- null;
    begin -- Check_P
       Ada.Text_IO.Put_Line
          (Item => "P = null => " & Boolean'Image (P = null) );

       if P /= null then
          Ada.Text_IO.Put_Line (Item => Integer'Image (P.F1) );
       end if;
    end Check_P;
end Pak1;

with Pak1;
procedure Test84 is
    -- null;
begin
    Create : declare
       X : Pak1.Rec1_Acc := new Pak1.Rec1;
    begin -- Create
       null;
    end Create;
exception -- Test84
when others =>
    Pak1.Check_P;
end Test84;

and get output:

P = null => FALSE
  123

I suppose P could be dangling, with the memory it points to not yet 
reused, but I suspect that is not the case.

-- 
Jeff Carter
"C++ is like jamming a helicopter inside a Miata
and expecting some sort of improvement."
Drew Olbrich
51



  reply	other threads:[~2007-09-12  0:34 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-09  7:40 Allocators and exceptions Maciej Sobczak
2007-09-09 12:17 ` anon
2007-09-09 20:31   ` Maciej Sobczak
2007-09-09 22:43     ` Simon Wright
2007-09-10 12:10       ` Maciej Sobczak
2007-09-10 19:08         ` Simon Wright
2007-09-10  2:56     ` anon
2007-09-10 12:42     ` Dmitry A. Kazakov
2007-09-10 21:48       ` Maciej Sobczak
2007-09-11  9:16         ` Dmitry A. Kazakov
2007-09-11  9:19           ` Maciej Sobczak
2007-09-11 12:27             ` Dmitry A. Kazakov
2007-09-11 19:07               ` Maciej Sobczak
2007-09-11 22:56                 ` Georg Bauhaus
2007-09-12 12:36                   ` Maciej Sobczak
2007-09-12 22:19                     ` Randy Brukardt
2007-09-12  9:32                 ` Dmitry A. Kazakov
2007-09-12 12:42                   ` Maciej Sobczak
2007-09-12 15:25                     ` Dmitry A. Kazakov
2007-09-12 12:29             ` Stephen Leake
2007-09-12 12:46               ` Maciej Sobczak
2007-09-12 20:53                 ` Simon Wright
2007-09-12 22:32                   ` Randy Brukardt
2007-09-12 23:43                     ` Simon Wright
2007-09-13  3:42                       ` Randy Brukardt
2007-09-13  3:36                     ` Randy Brukardt
2007-09-13  9:43                     ` Maciej Sobczak
2007-09-12 22:25                 ` Randy Brukardt
2007-09-13 11:51                 ` Stephen Leake
2007-09-12 14:14               ` Markus E L
2007-09-10 10:37 ` Allocators and exceptions => Read Me First anon
2007-09-10 12:16   ` Maciej Sobczak
2007-09-10 22:10     ` Allocators and exceptions => Trying Again anon
2007-09-10 23:15       ` Markus E L
2007-09-10 15:44 ` Allocators and exceptions Adam Beneschan
2007-09-10 21:58   ` Maciej Sobczak
2007-09-10 22:07   ` Jeffrey R. Carter
2007-09-11  9:14   ` Dmitry A. Kazakov
2007-09-11  9:23     ` Maciej Sobczak
2007-09-11  2:36 ` Randy Brukardt
2007-09-11 15:33   ` Adam Beneschan
2007-09-11 19:21     ` Maciej Sobczak
2007-09-11 21:56     ` Adam Beneschan
2007-09-12  0:34       ` Jeffrey R. Carter [this message]
2007-09-12 12:13         ` Maciej Sobczak
2007-09-12 16:34           ` Jeffrey R. Carter
2007-09-12 23:50             ` Jeffrey R. Carter
2007-09-12 12:22       ` Maciej Sobczak
2007-09-12 14:11         ` Markus E L
2007-09-12 16:08         ` Adam Beneschan
2007-09-12 20:35           ` Dmitry A. Kazakov
2007-09-12 21:01             ` Adam Beneschan
2007-09-12 22:45             ` Randy Brukardt
2007-09-13  7:48               ` Dmitry A. Kazakov
2007-09-12  3:08 ` Allocators and exceptions -- Debugging says memory leak! anon
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox