[Bug ada/11090] New: Variant Record Initialization.
bdavis9659@comcast.net
gcc-bugzilla@gcc.gnu.org
Wed Jun 4 18:46:00 GMT 2003
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11090
Summary: Variant Record Initialization.
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: critical
Priority: P1
Component: ada
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: bdavis9659@comcast.net
CC: gcc-bugs@gcc.gnu.org
GCC host triplet: i386/gnu/linux
Functions used in variant record initialization are called multiple times.
FYI, the VADS ada compiler will only call the function once.
------------------------------------------------------------------------------
Here is a test case that demonstrates the problem, followed by the output:
with text_io;
procedure varrec is
type my_enum_type1 is (A1, A2, A3, A4, A5, A6);
type my_enum_type2 is (B1, B2);
type my_integer is new integer range 0..190;
type var_rec_a (sel1 : my_enum_type1 := A4; sel2 : my_enum_type2 := B2) is
record
case sel1 is
when A4 | A3 | A1 | A2 =>
case sel1 is
when A3 | A1 | A2 =>
case sel1 is
when A3 =>
case sel2 is
when B1 =>
vary : integer;
when others =>
null;
end case;
when others =>
case sel2 is
when B2 =>
var3 : my_integer;
when others =>
null;
end case;
end case;
when others =>
case sel2 is
when B2 =>
varyy : integer;
when B1 =>
varzz : integer;
end case;
end case;
when others =>
case sel2 is
when B2 =>
varyyy : integer;
when B1 =>
varzzz : integer;
end case;
end case;
end record;
type var_rec_2 (sel1 : my_enum_type1 := A4) is
record
var1 : integer;
var2 : integer;
case sel1 is
when A4 | A3 | A1 | A2 | A6 =>
var_rec_1 : var_rec_a;
when A5 =>
varx : integer;
when others =>
null;
end case;
end record;
rec1 : var_rec_2(A2);
rec2 : var_rec_2(A2);
int_cnt : my_integer := my_integer'first;
function inc_int return my_integer is
begin
text_io.put(" int_cnt was : " & my_integer'image(int_cnt));
int_cnt := int_cnt + 1;
text_io.put_line(" : is : " & my_integer'image(int_cnt) & " :");
return int_cnt;
end inc_int;
begin
text_io.new_line;
text_io.new_line;
text_io.put_line("Initializing rec1");
text_io.put_line(" Note: inc_int is unexpectedly called more than once");
text_io.put_line(" when initializing the var3 field");
rec1 := (sel1 => A2,
var1 => 123,
var_rec_1 => (sel1 => A2,
sel2 => B2,
var3 => inc_int),
var2 => 456);
text_io.put_line("Done initializing rec1");
text_io.new_line;
text_io.put_line("Initializing rec2");
text_io.put_line(" Note: inc_int is unexpectedly called more than once");
text_io.put_line(" when initializing the var3 field");
rec2 := (sel1 => A2,
var1 => 123,
var_rec_1 => (sel1 => A2,
sel2 => B2,
var3 => inc_int),
var2 => 456);
text_io.put_line("Done initializing rec2");
text_io.new_line;
text_io.put_line("Printing var3 field in rec1 and then rec2.");
text_io.put_line(" Note: This is not what was expected.");
text_io.put_line(" Only expected inc_int to be called once,");
text_io.put_line(" with returned values of 1 and 2.");
text_io.put_line("rec1.var_rec_1.var3: " &
my_integer'image(rec1.var_rec_1.var3));
text_io.put_line("rec2.var_rec_1.var3: " &
my_integer'image(rec2.var_rec_1.var3));
end varrec;
--------------------------------------------------------------------------
Here is the current output:
Initializing rec1
Note: inc_int is unexpectedly called more than once
when initializing the var3 field
int_cnt was : 0 : is : 1 :
int_cnt was : 1 : is : 2 :
int_cnt was : 2 : is : 3 :
int_cnt was : 3 : is : 4 :
int_cnt was : 4 : is : 5 :
int_cnt was : 5 : is : 6 :
int_cnt was : 6 : is : 7 :
int_cnt was : 7 : is : 8 :
int_cnt was : 8 : is : 9 :
Done initializing rec1
Initializing rec2
Note: inc_int is unexpectedly called more than once
when initializing the var3 field
int_cnt was : 9 : is : 10 :
int_cnt was : 10 : is : 11 :
int_cnt was : 11 : is : 12 :
int_cnt was : 12 : is : 13 :
int_cnt was : 13 : is : 14 :
int_cnt was : 14 : is : 15 :
int_cnt was : 15 : is : 16 :
int_cnt was : 16 : is : 17 :
int_cnt was : 17 : is : 18 :
Done initializing rec2
Printing var3 field in rec1 and then rec2.
Note: This is not what was expected.
Only expected inc_int to be called once,
with returned values of 1 and 2.
rec1.var_rec_1.var3: 1
rec2.var_rec_1.var3: 10
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.
More information about the Gcc-bugs
mailing list