This next step in implementing Ada 2012 AI 142 adds the check that
the actual for an aliased parameter is itself aliased, as shown by
the following example:
1. pragma Ada_2012;
2. with Text_IO; use Text_IO;
3. procedure AliasP3 is
4. G : Integer;
5.
6. procedure K (R : aliased in out Integer) is
7. begin
8. G := 2;
9. R := 5;
10. Put_Line (G'Img);
11. end;
12. begin
13. K (G);
|
>>> actual for aliased formal "R" must be aliased object
14. end;
The previously filed test which is supposed to execute is modified
to be:
1. pragma Ada_2012;
2. with Text_IO; use Text_IO;
3. procedure AliasP1 is
4. G : aliased Integer;
5.
6. procedure K (R : aliased in out Integer) is
7. begin
8. G := 2;
9. R := 5;
10. Put_Line (G'Img);
11. end;
12. begin
13. K (G);
14. end;
which compiles fine and generates the output 5.
An additional test is filed showing aliased parameters working OK:
1. pragma Ada_2012;
2. with Text_IO; use Text_IO;
3. procedure AliasP2 is
4. G : aliased Integer;
5.
6. procedure K (R : aliased in out Integer) is
7. type A is access all Integer;
8. AA : A;
9. begin
10. G := 2;
11. AA := R'access;
12. AA.all := 6;
13. Put_Line (G'Img);
14. end;
15. begin
16. K (G);
17. end;
which compiles fine and generates the output 6
Tested on x86_64-pc-linux-gnu, committed on trunk
2011-09-01 Robert Dewar <[email protected]>
* exp_ch6.adb (Expand_Call): Check actual for aliased parameter is
aliased.
Index: exp_ch6.adb
===================================================================
--- exp_ch6.adb (revision 178381)
+++ exp_ch6.adb (working copy)
@@ -2208,8 +2208,8 @@
-- as we go through the loop, since this is a convenient place to do it.
-- (Though it seems that this would be better done in Expand_Actuals???)
- Formal := First_Formal (Subp);
- Actual := First_Actual (Call_Node);
+ Formal := First_Formal (Subp);
+ Actual := First_Actual (Call_Node);
Param_Count := 1;
while Present (Formal) loop
@@ -2235,7 +2235,7 @@
CW_Interface_Formals_Present
or else
(Ekind (Etype (Formal)) = E_Class_Wide_Type
- and then Is_Interface (Etype (Etype (Formal))))
+ and then Is_Interface (Etype (Etype (Formal))))
or else
(Ekind (Etype (Formal)) = E_Anonymous_Access_Type
and then Is_Interface (Directly_Designated_Type
@@ -2616,6 +2616,15 @@
end if;
end if;
+ -- For Ada 2012, if a parameter is aliased, the actual must be an
+ -- aliased object.
+
+ if Is_Aliased (Formal) and then not Is_Aliased_View (Actual) then
+ Error_Msg_NE
+ ("actual for aliased formal& must be aliased object",
+ Actual, Formal);
+ end if;
+
-- For IN OUT and OUT parameters, ensure that subscripts are valid
-- since this is a left side reference. We only do this for calls
-- from the source program since we assume that compiler generated
@@ -2667,9 +2676,7 @@
-- or IN OUT parameter! We do reset the Is_Known_Valid flag
-- since the subprogram could have returned in invalid value.
- if (Ekind (Formal) = E_Out_Parameter
- or else
- Ekind (Formal) = E_In_Out_Parameter)
+ if Ekind_In (Formal, E_Out_Parameter, E_In_Out_Parameter)
and then Is_Assignable (Ent)
then
Sav := Last_Assignment (Ent);