aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gnat.dg/unchecked_convert11.adb
blob: ad98a8814260ad24441cafbf7bb87414a079c558 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
-- { dg-do run }

with Unchecked_Conversion;

procedure Unchecked_Convert11 is

  subtype Unsigned_Type is Integer range 2_034 .. 2_164;

  subtype Signed_Type is Integer range -2048 .. 2047; 

  type Rec is record
    S : Signed_Type;
  end record;
  pragma Pack (Rec);

  function To_Signed_Type is
     new Unchecked_Conversion (Source => Unsigned_Type, Target => Rec);

  function To_Unsigned_Type is
     new Unchecked_Conversion (Source => Rec, Target => Unsigned_Type);

  Data : Unsigned_Type;
  Temp : Rec;

begin

  Data := 2100;
  Temp := To_Signed_Type (Data);
  if Temp.S /= -1996 then
    raise Program_Error;
  end if;
  Data := To_Unsigned_Type (Temp);
  if Data /= 2100 then
    raise Program_Error;
  end if;

  Data := 2047;
  Temp := To_Signed_Type (Data);
  if Temp.S /= 2047 then
    raise Program_Error;
  end if;
  Data := To_Unsigned_Type (Temp);
  if Data /= 2047 then
    raise Program_Error;
  end if;

end;