PR ipa/83051
[official-gcc.git] / gcc / testsuite / gnat.dg / unchecked_convert1.adb
blob1a02c195b7cb636b9b4eae04093d777df098d9da
1 -- { dg-do run }
2 -- { dg-options "-gnatws" }
4 with Ada.Unchecked_Conversion;
6 procedure Unchecked_Convert1 is
8 type Byte is mod 2**8;
10 type Stream is array (Natural range <>) of Byte;
12 type Rec is record
13 I1, I2 : Integer;
14 end record;
16 function Do_Sum (R : Rec) return Integer is
17 begin
18 return R.I1 + R.I2;
19 end;
21 function Sum (S : Stream) return Integer is
22 subtype Chunk is Stream (1 .. Rec'Size / 8);
23 function To_Chunk is new Ada.Unchecked_Conversion (Chunk, Rec);
24 begin
25 return Do_Sum (To_Chunk (S(S'First .. S'First + Rec'Size / 8 - 1)));
26 end;
28 A : Stream (1..9) := (others => 0);
29 I : Integer;
31 begin
32 A (9) := 1;
33 I := Sum (A(1..8));
34 end;