This is the mail archive of the
mailing list for the GCC project.
Re: Ada subtypes and base types
On Mar 16, 2006, at 05:09, Robert Dewar wrote:
Not quite right. If you have an uninitialized variable, the value is
invalid and may be out of bounds, but this is a bounded error
not an erroneous program. So the possible effects are definitely NOT
unbounded, and the use of such values cannot turn a program erroneous.
(that's an Ada 95 change, this used to be erroneous in Ada 83).
Actually, that's a good point and raises some potential issues:
if we're never establish the invariant that a value of a type is in
range, we can only use the base range for variables that might be
used uninitialized. Any read of such a variable would then involve
a range check.
package Uninitialized is
N : Positive;
procedure Test is
for J in 1 .. Uninitialized.N loop
In this case, GCC might replace the loop with
J : Integer := 1;
while J /= Uninitialized.N loop
J := J + 1;
which would be incorrect for N = 0.