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,ee82e0a06c8bbead X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.129.169 with SMTP id nx9mr1330077pbb.2.1333796952341; Sat, 07 Apr 2012 04:09:12 -0700 (PDT) Path: r9ni28721pbh.0!nntp.google.com!news2.google.com!volia.net!news2.volia.net!feed-A.news.volia.net!newsfeed.utanet.at!newsfeed.tele2net.at!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Ludovic Brenta Newsgroups: comp.lang.ada Subject: Re: A Gnother Gnasty bug Date: Sat, 07 Apr 2012 13:09:11 +0200 Organization: A noiseless patient Spider Message-ID: <87mx6nvlwo.fsf@ludovic-brenta.org> References: <22193583.1528.1333759470339.JavaMail.geo-discussion-forums@vbdn7> Mime-Version: 1.0 Injection-Info: mx04.eternal-september.org; posting-host="6xClJHSc8T7LsfSD0c42UQ"; logging-data="32713"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+p+JZQrHGt14YhoUx95YRx" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) Cancel-Lock: sha1:KmIq7j9+inAHGmwd+zndPekJR2U= sha1:DSR86tGyZxjCvz9IAQf/vCBM2Nw= Content-Type: text/plain; charset=us-ascii Date: 2012-04-07T13:09:11+02:00 List-Id: sbelmont700@gmail.com writes: > new I'class'(F(arg=> 42))))); I don't think that's legal. You can have a class-wide access value but not an allocator for a class-wide type because the allocator doesn't know how much memory to allocate: > 4.8(4): An initialized allocator is an allocator with a > qualified_expression. [...] Your allocator is initialized because it has a qualified_expression. > 4.8(7/2): For the evaluation of an initialized allocator, the > evaluation of the qualified_expression is performed first. An object > of the designated type is created and the value of the > qualified_expression is converted to the designated subtype and > assigned to the object. Now the allocator must create an object of the type designated by the qualified_expression. > 3.3(23): [...] A class-wide subtype is defined to have unknown > discriminants, and is therefore an indefinite subtype. An indefinite > subtype does not by itself provide enough information to create an > object; an additional constraint or explicit initialization expression > is necessary (see *note 3.3.1). The type designatd by your qualified_expression is class-wide, it is therefore impossible for the allocator to create the object. Therefore I think the compiler should have rejected your program. The fact that the value in the qualified_expression is the result of a function call fools the compiler. Here is a smaller example to demonstrate: with Ada.Finalization; procedure T is type B is new Ada.Finalization.Controlled with record D : Integer; end record; type Access_B is access B'Class; function F return B'Class is begin return B'(Ada.Finalization.Controlled with D => 42); end F; J : Access_B := new B'Class'(Ada.Finalization.Controlled with D => 42); -- Line 16 K : Access_B := new B'Class'(F); -- Line 17: Not diagnosed begin null; end T; gnatmake -gnatwa t gcc-4.4 -c -gnatwa t.adb t.adb:16:32: expected type "B'Class" defined at line 4 t.adb:16:32: found a composite type gnatmake: "t.adb" compilation error gnatmake -gnatwa t gcc-4.6 -c -gnatwa t.adb t.adb:16:32: expected type "B'Class" defined at line 4 t.adb:16:32: found a composite type So, the compiler correctly rejects line 16 but not line 17, even though both lines do exactly the same illegal thing. The correct way to call the allocator is, of course: J : Access_B := new B'(Ada.Finalization.Controlled with D => 42); K : Access_B := new B'(F); HTH -- Ludovic Brenta.