From: Tom Moran <tmoran@bix.com>
Subject: Adjust bug?
Date: 1997/07/18
Date: 1997-07-18T00:00:00+00:00 [thread overview]
Message-ID: <33CF1711.2A7E@bix.com> (raw)
This test program assigns the 'controlled' result from a function
to a variable. Two compilers create an intermediate anonymous object
and copy and adjust to it before copying and adjusting to the final
result. The third compiler does only the final adjust. Is this
legal according to 7.6(21)? Making the component 'id' aliased does
not change the behavior. The result is that the anonymous object
is eventually Finalized without ever having been Initialized or
Adjusted,
with sad results for my program. Is this a bug in the third compiler,
or a legal (though unfortunate) possibility?
with ada.finalization;
package testc is
type c_type is new ada.finalization.controlled with record
id:integer:=0;
end record;
function create return c_type;
procedure initialize(x:in out c_type);
procedure adjust (x:in out c_type);
procedure finalize (x:in out c_type);
end testc;
with ada.text_io;
with ada.unchecked_conversion;
package body testc is
type a is access all c_type;
function showa is new ada.unchecked_conversion(a,long_integer);
function create return c_type is
newborn:aliased c_type;
begin
ada.text_io.put_line("creating" & integer'image(newborn.id) &
long_integer'image(showa(newborn'unchecked_access)));
newborn.id:=7;
return newborn;
end create;
count:natural:=0;
procedure initialize(x:in out c_type) is
begin
count:=count+1;x.id:=count;
ada.text_io.put_line("init"
& integer'image(x.id) &
long_integer'image(showa(x'unchecked_access)));
end initialize;
procedure adjust (x:in out c_type) is
begin
ada.text_io.put_line("adj"
& integer'image(x.id) &
long_integer'image(showa(x'unchecked_access)));
end adjust;
procedure finalize(x:in out c_type) is
begin
ada.text_io.put_line("fin"
& integer'image(x.id) &
long_integer'image(showa(x'unchecked_access)));
end finalize;
end testc;
with ada.text_io,testc;
procedure test is
procedure try is
my_c:testc.c_type;
begin
ada.text_io.put_line("set");
my_c:=testc.create;
ada.text_io.put_line("did it");
end try;
begin
ada.text_io.put_line("start");
try;
ada.text_io.put_line("done");
end test;
two compilers questionable compiler
start start
init 1 39318880 init 1 5897228
set set
init 2 39318744 init 2 5897016
creating 2 39318744 creating 2 5897016
adj 7 73084948 fin 1 5897228
fin 7 39318744 adj 7 5897228
fin 1 39318880 fin 7 4587648
adj 7 39318880 did it
fin 7 73084948 fin 7 5897228
did it done
fin 7 39318880
done
next reply other threads:[~1997-07-18 0:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-07-18 0:00 Tom Moran [this message]
1997-07-18 0:00 ` Adjust bug? Tucker Taft
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox