Patchwork [Ada] Mode conformance for Ada 2012 aliased formal parameters

mail settings
Submitter Arnaud Charlet
Date June 14, 2012, 10:50 a.m.
Message ID <>
Download mbox | patch
Permalink /patch/164910/
State New
Headers show


Arnaud Charlet - June 14, 2012, 10:50 a.m.
In Ada 2012 formal parameters can be declared explicitly aliased. Mode
conformance now requires that both or neither formal be aliased.

Compiling alias.adb must yield:

alias.adb:7:13: not fully conformant with declaration at line 6
alias.adb:7:13: aliased parameter mismatch not subtype conformant with operation inherited at line 5 aliased parameter mismatch

package Alias is
   type R is tagged null record;
   procedure Change (Obj : R);

   type R2 is new R with null record;
     procedure Change (Obj : aliased R2);   --  ERROR
end Alias;
package body Alias is
   procedure Change (Obj : R) is begin null; end;
   procedure Change (Obj : aliased R2) is begin null; end;

   function check (Obj : R) return Integer;
   function check (Obj : aliased R) return Integer is   -- ERROR
      return R'Size;
end Alias;

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

2012-06-14  Ed Schonberg  <>

	* sem_ch6.adb (Check_Conformance): Add Ada 2012 check on mode
	conformance: "aliased" must apply to both or neither formal


Index: sem_ch6.adb
--- sem_ch6.adb	(revision 188605)
+++ sem_ch6.adb	(working copy)
@@ -5503,6 +5503,18 @@ 
             end if;
          end if;
+         --  Ada 2012:  mode conformance also requires that formal parameters
+         --  be both aliased, or neither.
+         if Ctype >= Mode_Conformant
+           and then Ada_Version >= Ada_2012
+         then
+            if Is_Aliased (Old_Formal) /= Is_Aliased (New_Formal) then
+               Conformance_Error
+                 ("\aliased parameter mismatch!", New_Formal);
+            end if;
+         end if;
          if Ctype = Fully_Conformant then
             --  Names must match. Error message is more accurate if we do