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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!nntp-feed.chiark.greenend.org.uk!ewrotcd!reality.xs3.de!news.jacob-sparre.dk!franka.jacob-sparre.dk!pnx.dk!.POSTED!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Generic formals and Aspects Date: Tue, 19 Jul 2016 14:23:31 -0500 Organization: JSA Research & Innovation Message-ID: References: <59656e9a-8826-490e-9c35-f13f8ff1aa91@googlegroups.com> <18aedafc-c66d-4bba-81ce-76dce495f59e@googlegroups.com> NNTP-Posting-Host: rrsoftware.com X-Trace: franka.jacob-sparre.dk 1468956207 24580 24.196.82.226 (19 Jul 2016 19:23:27 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Tue, 19 Jul 2016 19:23:27 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 Xref: news.eternal-september.org comp.lang.ada:31103 Date: 2016-07-19T14:23:31-05:00 List-Id: wrote in message news:18aedafc-c66d-4bba-81ce-76dce495f59e@googlegroups.com... > On Tuesday, July 19, 2016 at 6:05:12 PM UTC+2, Shark8 wrote: >> Try the following: >> >> >> ------ SPEC ------ >> generic >> type Discrete_Type is (<>); -- CANDIDATE >> >> package Big_Endian_Integer_Buffer is >> >> function Get return Discrete_Type; >> procedure Set (Value : Discrete_Type); >> >> Private >> type Internal is new Discrete_Type >> with Static_Predicate => Internal'Size in 16 | 32 | 64; You could use a subtype here, if you don't want a new type: subtype Internal is Discrete_Type with Dynamic_Predicate => Internal'Size in 16 | 32 | 64; BUT: 'Size shouldn't be allowed in either of these predicates, because "Internal" is a value (the value of the "current instance" of the subtype), while Size is the attribute of a subtype or object. (See AI12-0068-1.) This is necessary so that the properties of the object can't be queried in a predicate; that wasn't the purpose of predicates and it would allow some truly bizarre uses. (See "Zoofable" in the question of that AI.) Specifically, 8.6(17.1/4) says: Within an aspect_specification for a type or subtype, the current instance represents a value of the type; it is not an object. The nominal subtype of this value is given by the subtype itself (the first subtype in the case of a type_declaration), prior to applying any predicate specified directly on the type or subtype. If the type or subtype is by-reference, the associated object with the value is the object associated (see 6.2) with the execution of the usage name. AARM Ramification: For the purposes of Legality Rules, the current instance acts as a value within an aspect_specification. It might really be an object (and has to be for a by-reference type), but that isn't discoverable by direct use of the name of the current instance. Looks like an ACATS test is needed. >> Size_In_Bytes : constant Positive := Internal'Size / 8; ... ... > That said, after changing Static_Predicate to Dynamic_Predicate in the > spec, the test program builds okay. > However, it runs without failure. (I would have expected a failure on the > Fail instantiation.) Did you remember to enable assertions? GNAT has the Assertion_Policy as Ignore by default. (This is implementation-defined in the Standard, mainly because we didn't have enough votes to make GNAT change.) If you're depending on assertions (like a predicate), you always need to appropriately place a Assertion_Policy pragma (or the equivalent command-line option, whatever it is). Randy.