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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,ea5071f634c2ea8b,start X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.39.100 with SMTP id o4mr7891572pbk.0.1321737285056; Sat, 19 Nov 2011 13:14:45 -0800 (PST) Path: h5ni10909pba.0!nntp.google.com!news2.google.com!postnews.google.com!f29g2000yqa.googlegroups.com!not-for-mail From: Shark8 Newsgroups: comp.lang.ada Subject: Generic-Package Elaboration Question / Possible GNAT Bug. Date: Sat, 19 Nov 2011 13:14:44 -0800 (PST) Organization: http://groups.google.com Message-ID: <7bf9bc32-850a-40c6-9ae2-5254fe220533@f29g2000yqa.googlegroups.com> NNTP-Posting-Host: 24.230.151.194 Mime-Version: 1.0 X-Trace: posting.google.com 1321737284 2912 127.0.0.1 (19 Nov 2011 21:14:44 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sat, 19 Nov 2011 21:14:44 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: f29g2000yqa.googlegroups.com; posting-host=24.230.151.194; posting-account=lJ3JNwoAAAAQfH3VV9vttJLkThaxtTfC User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: HUALESNKRC X-HTTP-UserAgent: Mozilla/5.0 (Windows NT 6.1; rv:8.0) Gecko/20100101 Firefox/8.0,gzip(gfe) Xref: news2.google.com comp.lang.ada:14465 Content-Type: text/plain; charset=ISO-8859-1 Date: 2011-11-19T13:14:44-08:00 List-Id: 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 => Return Data( Index_Type'Succ(Index)..Data'Last ); when Index_Type'Last => Return Data( Data'First..Index_Type'Pred(Index) ); when others => 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 = Data'First then Return Data( Index_Type'Succ(Index)..Data'Last ); elsif Index = 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?)