From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Generic formals and Aspects
Date: Tue, 19 Jul 2016 14:23:31 -0500
Date: 2016-07-19T14:23:31-05:00 [thread overview]
Message-ID: <nmlunf$o04$1@franka.jacob-sparre.dk> (raw)
In-Reply-To: 18aedafc-c66d-4bba-81ce-76dce495f59e@googlegroups.com
<olivermkellogg@gmail.com> 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.
next prev parent reply other threads:[~2016-07-19 19:23 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-17 13:17 Generic formals and Aspects Simon Wright
2014-10-17 16:04 ` Shark8
2014-10-17 18:51 ` Simon Wright
2014-10-18 1:43 ` Shark8
2016-07-19 15:49 ` olivermkellogg
2016-07-19 16:04 ` J-P. Rosen
2016-07-19 16:05 ` Shark8
2016-07-19 18:00 ` olivermkellogg
2016-07-19 19:23 ` Randy Brukardt [this message]
2016-07-20 15:09 ` olivermkellogg
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox