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: a07f3367d7,de8112bdf65b223b X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit X-Received: by 10.224.189.78 with SMTP id dd14mr11788657qab.0.1359999169198; Mon, 04 Feb 2013 09:32:49 -0800 (PST) X-Received: by 10.49.71.169 with SMTP id w9mr1873368qeu.7.1359999169155; Mon, 04 Feb 2013 09:32:49 -0800 (PST) Path: k2ni6832qap.0!nntp.google.com!p13no10461526qai.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 4 Feb 2013 09:32:49 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ NNTP-Posting-Host: 66.126.103.122 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Inheritance of representation aspects From: Adam Beneschan Injection-Date: Mon, 04 Feb 2013 17:32:49 +0000 Content-Type: text/plain; charset=ISO-8859-1 Date: 2013-02-04T09:32:49-08:00 List-Id: On Sunday, February 3, 2013 8:27:20 AM UTC-8, Simon Wright wrote: > A question on Stack Overflow[1] asks about deriving from an unchecked > union. The questioner thinks that a derived type should also be > an unchecked union, but GNAT doesn't. > A demo is > > package Union is > type Access_Kind is (Named, Indexed); > type Array_Type is array (0 .. 1) of Integer; > > type Base (Kind : Access_Kind := Access_Kind'First) is record > case Kind is > when Named => > X, Y : Integer; > when Indexed => > S : Array_Type; > end case; > end record with > Unchecked_Union => True, > Convention => C_Pass_By_Copy; > > -- A primitive operation, freezes Base. > procedure P (R : Base) is null; > > -- Derived types should inherit both representation aspects, so > -- both these aspects should be confirming > type Derived_1 is new Base with Unchecked_Union => True; > type Derived_2 is new Base with Convention => C_Pass_By_Copy; > > -- This should fail (ARM 13.1(10)). > type Derived_3 is new Base with Unchecked_Union => False; > > end Union; > > Both Unchecked_Union and C_Pass_By_Copy are representation aspects, and > should therefore be inherited (I've given links at my SO answer[2]). So > the aspects specified for Derived_1 and Derived_2 should both be > confirming and therefore OK (?), while the aspect for Derived_3 should > be illegal by ARM 13.1(10). > > With GNAT GPL 2012 and GCC 4.8.0 (r195682), Derived_1 and Derived_2 fail > (representation item appears too late) and Derived_3 doesn't raise an > error. > > With GNAT GPL 2012, if I comment out Derived_1 and Derived_2, the > compilation is successful (with 4.8.0 I get a bug box, which is a > separate issue). > > Am I correct that these aspects should be inherited? You're right that they should be inherited (13.1(15)), and that the declaration of Derived_3 would be illegal. I'm not clear that Derived_1 and Derived_2 are legal, however. The aspect clauses are confirming, but there's no blanket rule that confirming aspect clauses are always legal. The rule in 13.1(10) says "For an untagged derived type, it is illegal to specify a type-related representation aspect if the parent type is a by-reference type, or has any user-defined primitive subprograms." So it's illegal, period. There is no exception here for confirming aspect clauses. -- Adam