Hi Laurent,

On Wednesday 22 February 2006 12:34, Laurent GUERBY wrote:
> On Wed, 2006-02-22 at 10:54 +0100, Richard Guenther wrote:
> > > > > >  type T1 is range 0 .. 127;
> > > > > >  -- Compiler will choose some type for T'Base, likely to be 
> > > > > > -128..127
> > > > > >  -- but could be Integer (implementation dependant)
> > > > > >  subtype T is T1 range 0 .. 100;
> > > > > >  R : T := 100+X-X;
> > > > > >  -- guaranteed work as long 100+X<=T'Base'Last and 
> > > > > > 100-X>=T'Base'First
> > 
> > Is the final "conversion" a checked conversion or an unchecked conversion?  
> > I.e.
> > are we supposed to check for overflow using 'Valid on the final result?  Or 
> > will
> > the value be truncated or a runtime error raised?
> 
> In the full language we are supposed to check the range on the
> assignement and raise the predefined exception "CONSTRAINT_ERROR" if it
> fails (whatever the way in the generated code). However GNAT by default
> does not generate this kind of check, you need to add -gnato to the
> compile flags.

my understanding is that -gnato causes the compiler to insert checks that the
"100+X-X" computation does not overflow the base type.  The compiler always
inserts a check that the result is in the range of the target type T before
performing the assignment, regardless of whether -gnato is set or not.

Best wishes,

Duncan.

Reply via email to