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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,ea5071f634c2ea8b X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,UTF8 Received: by 10.68.35.131 with SMTP id h3mr2425129pbj.1.1322018012690; Tue, 22 Nov 2011 19:13:32 -0800 (PST) Path: lh20ni7537pbb.0!nntp.google.com!news2.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!usenet-fr.net!gegeweb.org!aioe.org!.POSTED!not-for-mail From: =?utf-8?Q?Yannick_Duch=C3=AAne_=28Hibou57?= =?utf-8?Q?=29?= Newsgroups: comp.lang.ada Subject: Re: Generic-Package Elaboration Question / Possible GNAT Bug. Date: Wed, 23 Nov 2011 04:13:29 +0100 Organization: Ada @ Home Message-ID: References: <7bf9bc32-850a-40c6-9ae2-5254fe220533@f29g2000yqa.googlegroups.com> NNTP-Posting-Host: wgHBtatYse3YjKAUQsirEA.user.speranza.aioe.org Mime-Version: 1.0 X-Complaints-To: abuse@aioe.org User-Agent: Opera Mail/11.60 (Linux) X-Notice: Filtered by postfilter v. 0.8.2 Xref: news2.google.com comp.lang.ada:14539 Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes Content-Transfer-Encoding: Quoted-Printable Date: 2011-11-23T04:13:29+01:00 List-Id: A guess attempt: does not depend on Generic_Delete implementation, but = rather on a Generic_Delete instantiation parameters. If you could post t= he = instantiation snippet too=E2=80=A6 (with declarations it depends on). Le Sat, 19 Nov 2011 22:14:44 +0100, Shark8 a = = =C3=A9crit: > I was working on some simple little array manipulation functions when > I encountered an interesting behavior in the compiler; it said that > trying to instantiate a function of the form: > Generic > Type Element is Private; > Type Index_Type is (<>); > Type Array_Type is Array (Index_Type Range <>) of Element; > Function Generic_Delete( Index : In Index_Type; Data : In > Array_Type ) Return Array_Type; > > When given the following body, the compiler complained about the > Index_Range'First/Last not being static: > > Function Generic_Delete( Index : In Index_Type; Data : In > Array_Type ) Return Array_Type is > begin > if Index not in Data'Range then > Raise Constraint_Error; > else > case Index is > when Index_Type'First =3D> Return > Data( Index_Type'Succ(Index)..Data'Last ); > when Index_Type'Last =3D> Return > Data( Data'First..Index_Type'Pred(Index) ); > when others =3D> > Return Data( Data'First..Index_Type'Pred(Index) ) > & Data( Index_Type'Succ(Index)..Data'Last ); > end case; > end if; > end Generic_Delete; > > Now, I know that the following works as a fix: > > Function Generic_Delete( Index : In Index_Type; Data : In > Array_Type ) Return Array_Type is > begin > if Index not in Data'Range then > Raise Constraint_Error; > else > if Index =3D Data'First then > Return Data( Index_Type'Succ(Index)..Data'Last ); > elsif Index =3D Data'Last then > Return Data( Data'First..Index_Type'Pred(Index) ); > else > Return Data( Data'First..Index_Type'Pred(Index) ) > & Data( Index_Type'Succ(Index)..Data'Last ); > end if; > end if; > end Generic_Delete; > > But the question that came to my mind after reading the ARM section on= > the error (sorry, I forgot to write it down) is, why is it not static?= > Is it because though the elaboration-parameters *may* be known [and > static] at compile-time that some instantiation might NOT be > [guaranteed] to be known at compile-time? (i.e. because the compiler > cannot guarantee that you won't throw 1..N where N is something pulled= > from the user-input?) -- = =E2=80=9CSyntactic sugar causes cancer of the semi-colons.=E2=80=9D [Ep= igrams on = Programming =E2=80=94 Alan J. =E2=80=94 P. Yale University] =E2=80=9CStructured Programming supports the law of the excluded muddle.= =E2=80=9D [Idem]