This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] Check that actual for aliased parameter is aliased


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  <dewar@adacore.com>

	* exp_ch6.adb (Expand_Call): Check actual for aliased parameter is
	aliased.

Attachment: difs
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]