| 1 |
-- PR ada/114398 |
| 2 |
-- Testcase by Dennis van Raaij <[email protected]> |
| 3 |
|
| 4 |
-- { dg-do run } |
| 5 |
|
| 6 |
with Ada.Finalization; |
| 7 |
|
| 8 |
procedure Access11 is |
| 9 |
|
| 10 |
package Pkg is |
| 11 |
|
| 12 |
type Int is |
| 13 |
new Ada.Finalization.Limited_Controlled |
| 14 |
with record |
| 15 |
Value : Integer; |
| 16 |
end record; |
| 17 |
|
| 18 |
procedure Set (This : out Int; To : Integer); |
| 19 |
procedure Set (This : out Int; To : Int); |
| 20 |
|
| 21 |
function "+" (Left, Right : Int) return Int; |
| 22 |
|
| 23 |
overriding procedure Initialize (This : in out Int); |
| 24 |
overriding procedure Finalize (This : in out Int); |
| 25 |
|
| 26 |
end Pkg; |
| 27 |
|
| 28 |
package body Pkg is |
| 29 |
|
| 30 |
procedure Set (This : out Int; To : Integer) is |
| 31 |
begin |
| 32 |
This.Value := To; |
| 33 |
end Set; |
| 34 |
|
| 35 |
procedure Set (This : out Int; To : Int) is |
| 36 |
begin |
| 37 |
This.Value := To.Value; |
| 38 |
end Set; |
| 39 |
|
| 40 |
function "+" (Left, Right : Int) return Int is |
| 41 |
begin |
| 42 |
return Result : Int do |
| 43 |
Result.Value := Left.Value + Right.Value; |
| 44 |
end return; |
| 45 |
end "+"; |
| 46 |
|
| 47 |
overriding procedure Initialize (This : in out Int) is |
| 48 |
begin |
| 49 |
This.Value := 42; |
| 50 |
end Initialize; |
| 51 |
|
| 52 |
overriding procedure Finalize (This : in out Int) is |
| 53 |
begin |
| 54 |
This.Value := 0; |
| 55 |
end Finalize; |
| 56 |
|
| 57 |
end Pkg; |
| 58 |
|
| 59 |
use Pkg; |
| 60 |
|
| 61 |
type Binary_Operator is access |
| 62 |
function (Left, Right : Int) return Int; |
| 63 |
|
| 64 |
procedure Test |
| 65 |
(Op : Binary_Operator; |
| 66 |
Left, Right : Int) |
| 67 |
is |
| 68 |
Result : Int; |
| 69 |
begin |
| 70 |
Result.Set (Op (Left, Right)); |
| 71 |
end Test; |
| 72 |
|
| 73 |
A, B : Int; |
| 74 |
|
| 75 |
begin |
| 76 |
A.Set (7); |
| 77 |
B.Set (9); |
| 78 |
|
| 79 |
Test ("+"'Access, A, B); |
| 80 |
end; |