| 1 |
-- { dg-do run } |
| 2 |
|
| 3 |
with Unchecked_Conversion; |
| 4 |
|
| 5 |
procedure Unchecked_Convert12 is |
| 6 |
|
| 7 |
subtype Unsigned_Type is Integer range 2_034 .. 2_164; |
| 8 |
|
| 9 |
subtype Signed_Type is Integer range -2048 .. 2047; |
| 10 |
|
| 11 |
type Rec is record |
| 12 |
S : Unsigned_Type; |
| 13 |
end record; |
| 14 |
pragma Pack (Rec); |
| 15 |
|
| 16 |
function To_Signed_Type is |
| 17 |
new Unchecked_Conversion (Source => Rec, Target => Signed_Type); |
| 18 |
|
| 19 |
function To_Unsigned_Type is |
| 20 |
new Unchecked_Conversion (Source => Signed_Type, Target => Rec); |
| 21 |
|
| 22 |
Data : Signed_Type; |
| 23 |
Temp : Rec; |
| 24 |
|
| 25 |
begin |
| 26 |
|
| 27 |
Data := -1996; |
| 28 |
Temp := To_Unsigned_Type (Data); |
| 29 |
if Temp.S /= 2100 then |
| 30 |
raise Program_Error; |
| 31 |
end if; |
| 32 |
Data := To_Signed_Type (Temp); |
| 33 |
if Data /= -1996 then |
| 34 |
raise Program_Error; |
| 35 |
end if; |
| 36 |
|
| 37 |
Data := 2047; |
| 38 |
Temp := To_Unsigned_Type (Data); |
| 39 |
if Temp.S /= 2047 then |
| 40 |
raise Program_Error; |
| 41 |
end if; |
| 42 |
Data := To_Signed_Type (Temp); |
| 43 |
if Data /= 2047 then |
| 44 |
raise Program_Error; |
| 45 |
end if; |
| 46 |
|
| 47 |
end; |