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=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.107.40.17 with SMTP id o17mr12163042ioo.29.1469027379073; Wed, 20 Jul 2016 08:09:39 -0700 (PDT) X-Received: by 10.157.14.230 with SMTP id 93mr2266406otj.17.1469027379042; Wed, 20 Jul 2016 08:09:39 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!news.glorb.com!f6no2961558ith.0!news-out.google.com!d68ni955ith.0!nntp.google.com!f6no2961555ith.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 20 Jul 2016 08:09:38 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=93.208.101.209; posting-account=Md_OIgoAAAAkZyQ6nYoc3WBIThMpPfV7 NNTP-Posting-Host: 93.208.101.209 References: <59656e9a-8826-490e-9c35-f13f8ff1aa91@googlegroups.com> <18aedafc-c66d-4bba-81ce-76dce495f59e@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <0bdf24b9-4a3d-43c2-8582-55d83b8b25ab@googlegroups.com> Subject: Re: Generic formals and Aspects From: olivermkellogg@gmail.com Injection-Date: Wed, 20 Jul 2016 15:09:39 +0000 Content-Type: text/plain; charset=UTF-8 Xref: news.eternal-september.org comp.lang.ada:31111 Date: 2016-07-20T08:09:38-07:00 List-Id: On Tuesday, July 19, 2016 at 9:23:34 PM UTC+2, Randy Brukardt wrote: > >> [...] > >> 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). > Yes, I added both pragma Assertion_Policy (Check); on the package spec and "-gnata" on compiling; no change on execution. Thanks for your insights.