From: Christoph Grein <christoph.grein@eurocopter.com>
To: comp.lang.ada@ada.eu.org
Subject: Re: Static assertions
Date: Fri, 18 May 2001 07:34:57 +0200 (MET DST)
Date: 2001-05-18T07:34:57+02:00 [thread overview]
Message-ID: <mailman.990164357.8926.comp.lang.ada@ada.eu.org> (raw)
Robert A Duff wrote:
> Interesting. But shouldn't it be Assert'(...)?
> ^ ie a qualified expression
package Verifier is
subtype Assert is Boolean range True .. True;
Assert_1 : constant := Boolean'Pos (Assert (Integer'Size = 16));
Assert_2 : constant := Boolean'Pos
(Assert (Integer'Size = 2 * Character'Size));
end Verifier;
With a type conversion this compiles on my Apex Ada 95 Compiler 3.0.0b on
Solaris and produces "0 0", with a qualified expression, it gives me the error
message:
Boolean'Pos (Assert'(Integer'Size = 16)) is disallowed since it is static and
will raise Constraint_Error [RM_95 4.9(34)]
It seems like the type conversion is ignored.
ARM 4.6(28)
For the evaluation of a type_conversion that is a value conversion, the operand
is evaluated, and then the value of the operand is converted to a corresponding
value of the target type, if any. If there is no value of the target type that
corresponds to the operand value, Constraint_Error is raised[; this can only
happen on conversion to a modular type, and only when the operand value is
outside the base range of the modular type.] Additional rules follow:
ARM 4.6(34) Enumeration Type Conversion
ARM 4.6(35)
The result is the value of the target type with the same position number as that
of the operand value.
Thus there is nowhere specified that the subtype range is checked.
Put_Line (Integer'Image (Natural (-2.3)));
compiles just fine and produces -2.
ARM 4.7(4)
The evaluation of a qualified_expression evaluates the operand (and if of a
universal type, converts it to the type determined by the subtype_mark) and
checks that its value belongs to the subtype denoted by the subtype_mark. The
exception Constraint_Error is raised if this check fails.
So thanx to Robert Duff for hinting.
Christoph Grein
next reply other threads:[~2001-05-18 5:34 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-05-18 5:34 Christoph Grein [this message]
2001-05-18 13:38 ` Static assertions Robert A Duff
2001-05-18 16:15 ` Jeffrey Carter
2001-05-18 17:25 ` Ted Dennison
2001-05-18 21:27 ` Robert A Duff
2001-05-18 22:46 ` Jeffrey Carter
2001-05-19 22:53 ` Robert A Duff
-- strict thread matches above, loose matches on Subject: below --
2001-05-17 15:07 Jean-Pierre Rosen
2001-05-17 17:44 ` Jeffrey Carter
2001-05-17 19:09 ` Marin David Condic
2001-05-17 22:34 ` Jeffrey Carter
2001-05-18 13:39 ` Marin David Condic
2001-05-18 1:23 ` Robert A Duff
2001-05-19 7:40 ` David Kristola
2001-05-19 22:56 ` Robert A Duff
2001-05-19 8:36 ` Aaro Koskinen
2001-05-21 7:50 ` Jean-Pierre Rosen
2001-06-12 3:59 ` David Thompson
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox