Patchwork [Ada] Aliasing and objects in extended return statements

login
register
mail settings
Submitter Arnaud Charlet
Date Oct. 14, 2011, 3:05 p.m.
Message ID <20111014150532.GA14721@adacore.com>
Download mbox | patch
Permalink /patch/119819/
State New
Headers show

Comments

Arnaud Charlet - Oct. 14, 2011, 3:05 p.m.
AI05-0053 forbids the use of the aliased keyword in the object declaration of an
extended return statement. This avoids semantic complications with return
objects that are not of an immutably limited type, and which therefore  are not
necesarily built in place.

Compiling the following in -gnat12 mode must yield:

   illegal_alias.adb:15:26: "aliased" not allowed in extended return

Compiling it in gnat05 mode must yield:

illegal_alias.adb:15:26: warning:
        "aliased" not allowed in extended return in Ada2012

---
procedure Illegal_Alias is
   type Outer;
   type Inner (Ref : access Outer) is limited null record;
   type Outer is limited
      record
          Self : Inner (Outer'Access);
          Data : Integer := 0;
      end record;

   type Vector is array (Positive range <>) of Outer;
   subtype S is Vector (1 .. 10);

   function F return Vector is
   begin
      return X : aliased Vector := S'(others => <>); --  ERROR
   end F;

begin
   null;
end Illegal_Alias;

Tested on x86_64-pc-linux-gnu, committed on trunk

2011-10-14  Ed Schonberg  <schonberg@adacore.com>

	* par-ch6.adb (P_Return_Object_Declaration): In Ada 2012 mode,
	reject an aliased keyword on the object declaration of an extended
	return statement. In older versions of the language indicate
	that this is illegal in the standard.

Patch

Index: par-ch6.adb
===================================================================
--- par-ch6.adb	(revision 179984)
+++ par-ch6.adb	(working copy)
@@ -1677,6 +1677,14 @@ 
          Scan; -- past ALIASED
          Set_Aliased_Present (Decl_Node);
 
+         if Ada_Version < Ada_2012 then
+            Error_Msg_SC -- CODEFIX
+              ("ALIASED not allowed in extended return in Ada2012?");
+         else
+            Error_Msg_SC -- CODEFIX
+              ("ALIASED not allowed in extended return");
+         end if;
+
          if Token = Tok_Constant then
             Scan; -- past CONSTANT
             Set_Constant_Present (Decl_Node);