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,9dcaa9f073e2ef8f X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!d26g2000prn.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Type in allocator has deeper level than designated class-wide type Date: Mon, 13 Jun 2011 18:24:51 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <9bf2ef73-5cc7-4863-90d7-2e2cf3bcd294@o10g2000prn.googlegroups.com> <92fb5bf2-f43e-4ac9-97eb-6092f10e5607@e17g2000prj.googlegroups.com> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1308014691 27958 127.0.0.1 (14 Jun 2011 01:24:51 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 14 Jun 2011 01:24:51 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: d26g2000prn.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: ARLUEHNKC X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; WOW64; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618; .NET4.0C),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:19806 Date: 2011-06-13T18:24:51-07:00 List-Id: On Jun 13, 6:07=A0pm, Adrian Hoe wrote: > I changed the line in procedure Add from > > =A0 =A0 =A0 New_Element :=3D new Element_Record' > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ( Constructor.Init ( Name= , Color, Data) ) ; > > to > > =A0 =A0 =A0 New_Element :=3D new Element_Record; > > The compiler is still pointing the same warning to this line. > > What exactly does the warning message "Type in allocator has deeper > level than designated class-wide type" mean? Is the compiler unable to > determine the size of the array during allocation? Or the array is a > level deeper than the List.Access_Node? It has nothing to do with arrays. When you declare a type as "access all T'Class", an object of that type can't be made to point to a type declared in a more deeply nested subprogram. A simple example: package Pack1 is type Root is tagged null record; type Acc is access all Root'Class; end Pack1; package Pack2 is procedure Proc1; end Pack2; with Pack1; package body Pack2 is procedure Proc1 is type Child is new Pack1.Root with null record; A : Pack1.Acc; begin A :=3D new Child; -- ILLEGAL end Proc1; end Pack2; This assignment statement is illegal, because somewhere later, A could be copied to, say, another variable of type Pack1.Acc declared globally in the body of Pack2, and then you'd have a pointer to a Child that would exist after Proc1 has exited and the Child type no longer exists, which is a big no-no. 4.8(5.1) prohibits this. Since in this case, the record type (Element_Record) is declared in a generic, that complicates things, because the generic *could* be instantiated inside a procedure, which would lead to the same sort of problem as above. I don't remember all the rules, but depending on where the type is declared and where the allocator occurs (generic specification or body), it might be illegal to instantiate this generic inside a procedure, or it might cause Program_Error to be raised. I just tried our compiler again and modified the source to instantiate High_Cloud; if there's an instance of High_Cloud inside a procedure, it *does* give a warning that Program_Error will be raised (if the "new Element_Record" expression is reached). If your compiler gives the warning when the generic is first seen, before an instance of the generic is seen, that's just a choice your compiler makes. But unless your program is arranged in a different order than I'm guessing, or unless there are some new Ada 2012 rules that I'm not yet familiar with, the compiler should not reject your generic, and it should not reject it or cause Program_Error to be raised if there's an instance of the generic that is *not* inside a subprogram. -- Adam