We recently updated GCC versions (4.8.2 to 5.3.0) and started receiving unexpected constraint errors in some Ada applications. I've reduced it to the following:
-- moo.adb
with text_io;
procedure moo is
type thing_type is (something1,something2,something3,something4,something5,something6);
for thing_type use (something1 => 1,something2 => 2,something3 =>
3,something4 => 4,something5 => 5,something6 => 6);
for thing_type'size use 32;
type thing_array_t is array (0 .. 5) of thing_type;
thing_array : thing_array_t := (others => something1);
begin
text_io.put_line("item 0 = " & thing_type'image(thing_array(0)));
end moo;
This program will compile just fine on either GCC version (simply compiled with "gnatmake moo.adb".) When built with 4.8.2, the output is as expected:
item 0 = SOMETHING1
When built with 5.0.3, we instead receive
raised CONSTRAINT_ERROR : moo.adb:13 invalid data
Interestingly, the results are exactly the same when compiled as 32 and 64 bit. Many things can be changed to make the program work fine with 5.3.0: removing the thing_type'size clause, adding or removing values to the enumerator, changing the number of items in the array, using a different value for initializing the array, etc. Are there any obvious problems with this code that could account for this behavior?