comp.lang.ada
 help / color / mirror / Atom feed
* Default comparison of tagged variant records
@ 2006-12-08 13:49 msimonides
  2006-12-08 18:30 ` Adam Beneschan
  0 siblings, 1 reply; 5+ messages in thread
From: msimonides @ 2006-12-08 13:49 UTC (permalink / raw)


I'm having problem with default comparison of tagged, variant records
not calling user-defined "=" operators for record components. At least
that's, what I think.

Here is an example:

with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Text_IO; use Ada.Text_IO;

procedure Test is

   type Thing is tagged
      record
         null;
      end record;

   type Bigger_Thing (Discriminant : Boolean) is new Thing with
      record
         case Discriminant is
            when True =>
               Text           : Unbounded_String;
            when False =>
               Number         : Natural;
         end case;
      end record;

   Big_Something        : constant Bigger_Thing := Bigger_Thing'(
      Discriminant => True, Text => Null_Unbounded_String);
   Big_Something_Copy   : constant Bigger_Thing := Big_Something;

begin
   Put_Line ("Are they equal?");
   Put_Line (Boolean'Image (Big_Something = Big_Something_Copy));
end Test;


It prints "FALSE" and does it for both values of Discriminant, so even
when Text component isn't used.
However, comparison works properly when either there is no
Unbounded_String, the record isn't tagged or the record doesn't have a
discriminant.

I have read a few threads on predefined operator reemergance on this
list and have looked at relevant parts of RM (ie. on generic formal
parameters, predefined operations and equality operator inheritance)
but it seems that my case isn't covered there.

Could you please shed some light on it? For now I have defined an
equality operator for the type in question.

I'm using GNAT GPL 2006.
-- 
Marcin Simonides




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-12-11 23:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-12-08 13:49 Default comparison of tagged variant records msimonides
2006-12-08 18:30 ` Adam Beneschan
2006-12-09  1:38   ` Randy Brukardt
2006-12-11  7:40     ` msimonides
2006-12-11 23:12       ` Randy Brukardt

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