comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <stephen_leake@stephe-leake.org>
Subject: Re: Unchecked_Union with empty variant
Date: Mon, 16 Mar 2009 17:52:54 -0400
Date: 2009-03-16T17:52:54-04:00	[thread overview]
Message-ID: <867i2p16fd.fsf@stephe-leake.org> (raw)
In-Reply-To: gpj045$4dc$1@octagram.motzarella.org

Ivan Levashew <octagram@bluebottle.com> writes:

> [Check_Unions.adb]
> ~~~~~~~~
> procedure Check_Unions is
>
>
> type Complex_Record (Kind : Integer := 0) is record
>    Constant_Part : Character;
>    Constant_Part2 : Character;
>    case Kind is
>    when 0 =>
>      Variant_Part1 : Character;
>    when 1 =>
>      Variant_Part2 : Character;
>    when 2 =>
>      Variant_Part3 : Character;
>    when others =>
>      null;
>    end case;
> end record;
>
> pragma Unchecked_Union (Complex_Record);
>
> begin
>    null;
> end Check_Unions;
> ~~~~~~~~
>
> It gives an error:
> C:\...ramming\GEMA-Win32API\Ada_test>gnatmake -gnat05 Check_Unions.adb
> gcc -c -gnat05 check_unions.adb
> check_unions.adb:14:04: Unchecked_Union may not have empty component list
> gnatmake: "check_unions.adb" compilation error
>
> What's the problem?
>
> I can't see any words "empty" or "null" here:
>
> http://www.adaic.com/standards/05aarm/html/AA-B-3-3.html

There is 14/2:

    All objects of an unchecked union type have the same size.

GNAT may be interpreting that to mean all variants must be the same
size. But that's not true, it accepts an Integer:

   type Complex_Record (Kind : Integer := 0) is record
      Constant_Part : Character;
      Constant_Part2 : Character;
      case Kind is
      when 0 =>
         Variant_Part1 : Character;
      when 1 =>
         Variant_Part2 : Integer;
      when 2 =>
         Variant_Part3 : Character;
      when others =>
         Variant_Part4 : Character;
      end case;
   end record;

So it looks like a compiler bug.

-- 
-- Stephe



  parent reply	other threads:[~2009-03-16 21:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-15 13:34 Unchecked_Union with empty variant Ivan Levashew
2009-03-16 15:16 ` Adam Beneschan
2009-03-16 21:52 ` Stephen Leake [this message]
2009-03-17  7:21   ` Ivan Levashew
  -- strict thread matches above, loose matches on Subject: below --
2009-03-15 13:10 Ivan Levashew
2009-03-15 13:02 Ivan Levashew
replies disabled

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