From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,eb6a9ac6a74a256c X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news1.google.com!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post02.iad.highwinds-media.com!news.flashnewsgroups.com-b7.4zTQh5tI3A!not-for-mail Newsgroups: comp.lang.ada Subject: Re: Unchecked_Union with empty variant References: From: Stephen Leake Date: Mon, 16 Mar 2009 17:52:54 -0400 Message-ID: <867i2p16fd.fsf@stephe-leake.org> User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) Cancel-Lock: sha1:YKMmxHR4IId9WX8Bsjft6SPOVKs= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: abuse@flashnewsgroups.com Organization: FlashNewsgroups.com X-Trace: 8a77e49beca36c77fb68831417 Xref: g2news2.google.com comp.lang.ada:5120 Date: 2009-03-16T17:52:54-04:00 List-Id: Ivan Levashew 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