comp.lang.ada
 help / color / mirror / Atom feed
From: msimonides@power.com.pl
Subject: Default comparison of tagged variant records
Date: 8 Dec 2006 05:49:28 -0800
Date: 2006-12-08T05:49:28-08:00	[thread overview]
Message-ID: <1165585768.342140.201110@16g2000cwy.googlegroups.com> (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




             reply	other threads:[~2006-12-08 13:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-08 13:49 msimonides [this message]
2006-12-08 18:30 ` Default comparison of tagged variant records Adam Beneschan
2006-12-09  1:38   ` Randy Brukardt
2006-12-11  7:40     ` msimonides
2006-12-11 23:12       ` Randy Brukardt
replies disabled

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