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
alias.ads:7:24: not subtype conformant with operation inherited at line 5
alias.ads:7:24: aliased parameter mismatch

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

   type R2 is new R with null record;
   overriding
     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
   begin
      return R'Size;
   end;
end Alias;

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

2012-06-14  Ed Schonberg  <schonb...@adacore.com>

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

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

Reply via email to