diff mbox

[Ada] Ada2012 freeze rules for subprogram profiles

Message ID 20141010144304.GA1703@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet Oct. 10, 2014, 2:43 p.m. UTC
Ada05-019 specifies that freezing a subprogram does not automatically freeze
the profile, i.e. the types of the formals and the return type. In particular
an attribute reference 'Access and its relatives do not freeze the profile.

Compiling bd.ads must yield:

   bd.ads:15:34: incorrect expression for "READ" attribute

---
with Ada.Streams;
package BD is
    type My_Big_Int is range 0 .. 10000;

    type Write_Ptr is access procedure
       (Stream : not null access Ada.Streams.Root_Stream_Type'Class;
        A      : in My_Big_Int'Base);

    procedure Good_Write6
       (Stream : not null access Ada.Streams.Root_Stream_Type'Class;
        A      : in My_Big_Int'Base);

    WPtr : Write_Ptr := Good_Write6'Access;
                        -- Does not freeze My_Big_Int (AI05-0019-1).
    for My_Big_Int'Read use WPtr.all;  -- ERROR:

private
    type My_Priv (D : Integer) is null record;
end BD;

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

2014-10-10  Ed Schonberg  <schonberg@adacore.com>

	* freeze.adb (Freeze_Entity): Freezing a subprogram does
	not always freeze its profile.	In particular, an attribute
	reference that takes the access type does not freeze the types
	of the formals.
diff mbox

Patch

Index: freeze.adb
===================================================================
--- freeze.adb	(revision 216089)
+++ freeze.adb	(working copy)
@@ -4004,7 +4004,17 @@ 
             --  any extra formal parameters are created since we now know
             --  whether the subprogram will use a foreign convention.
 
-            if not Is_Internal (E) then
+            --  In Ada 2012, freezing a subprogram does not always freeze
+            --  the corresponding profile (see AI05-019). An attribute
+            --  reference is not a freezing point of the profile.
+            --  Other constructs that should not freeze ???
+
+            if Ada_Version > Ada_2005
+              and then Nkind (N) = N_Attribute_Reference
+            then
+               null;
+
+            elsif not Is_Internal (E) then
                declare
                   F_Type    : Entity_Id;
                   R_Type    : Entity_Id;