From: "Björn Persson" <spam-away@nowhere.nil>
Subject: Is this definition legal?
Date: Sat, 18 Sep 2004 23:29:57 GMT
Date: 2004-09-18T23:29:57+00:00 [thread overview]
Message-ID: <Vx33d.3580$d5.27722@newsb.telia.net> (raw)
GCC-Gnat 3.4.0 is having serious problems with the definition of
Character_Encoding below:
type Known_OS is (NT, OS2, Linux);
This_OS : constant Known_OS := Linux;
type Encoding_ID is
(UTF_8_ID, ASCII_ID, Latin_1_ID); -- and some others
type Unified_Encoding_Record (Known : Boolean; OS : Known_OS) is record
case Known is
when True =>
Which : Encoding_ID;
when False =>
case OS is
when Linux =>
Name : Unbounded_String;
when NT | OS2 =>
Number : Unsigned_16;
end case;
end case;
end record;
type Character_Encoding (Known : Boolean := False) is
new Unified_Encoding_Record (Known => Known, OS => This_OS);
Gnat often crashes with a bug box on a reference to Character_Encoding.
For example, when I declare a variable of this type I have to initialize
it at the declaration to avoid a bug box. Also, the predefined "=" for
Character_Encoding sometimes returns False for values that should be equal.
Once when I converted a Character_Encoding to a Unified_Encoding_Record,
the field OS was set to NT, even though This_OS = Linux. The next
conversion raised Constraint_Error with the message "invalid data".
My first question is: Is this definition of Character_Encoding legal and
I should work around the problems until Gnat gets fixed, or is it
illegal code that Gnat fails to reject, and I should find another way to
do it?
I have also seen an indication that Adjust gets called on the field Name
(Unbounded_String is controlled), even when Known is True, and this is
my second question: Should I expect that fields in a variant part are
"active" like this even when they are inaccessible because of the
discriminant's value? It seems like waste of time to call procedures to
maintain a value that can never be read.
--
Björn Persson PGP key A88682FD
omb jor ers @sv ge.
r o.b n.p son eri nu
next reply other threads:[~2004-09-18 23:29 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-09-18 23:29 Björn Persson [this message]
2004-09-18 23:44 ` Is this definition legal? Ludovic Brenta
2004-09-19 14:07 ` Björn Persson
2004-09-19 20:21 ` Ludovic Brenta
2004-09-23 21:18 ` Björn Persson
2004-09-19 14:17 ` Björn Persson
2004-09-19 8:42 ` Martin Krischik
2004-09-19 11:25 ` Simon Wright
2004-09-20 7:32 ` Martin Krischik
2004-09-20 13:44 ` Björn Persson
2004-09-20 16:01 ` Martin Krischik
2004-09-20 21:20 ` Randy Brukardt
2004-09-20 17:12 ` Florian Weimer
2004-09-21 7:58 ` Martin Krischik
2004-09-19 11:30 ` Simon Wright
2004-09-19 11:53 ` Martin Dowie
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox