Patchwork [Ada] Illegal prefix in array attributes

login
register
mail settings
Submitter Arnaud Charlet
Date Jan. 2, 2013, 11:53 a.m.
Message ID <20130102115343.GA23714@adacore.com>
Download mbox | patch
Permalink /patch/209012/
State New
Headers show

Comments

Arnaud Charlet - Jan. 2, 2013, 11:53 a.m.
A reference to a type in an expression freezes the type, and any component
subtypes. This is the case for array attributes such as 'Length, 'Size, etc.
which can be evaluated without reference to the component type, but still
require that the component type be fully declared at the point of the attribute.

Compiling foo.ads must yield:

  foo.ads:5:21: premature usage of incomplete private type "X" defined at line 3

package Foo is

    type X is private;    
    type Y is array(1 .. 4) of X;    
    Z : constant := Y'Length;

private
    type X is new Integer;    

end Foo;

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

2013-01-02  Ed Schonberg  <schonberg@adacore.com>

	* sem_attr.adb (Check_Array_Type): Reject an attribute reference on an
	array whose component type does not have a completion.

Patch

Index: sem_attr.adb
===================================================================
--- sem_attr.adb	(revision 194792)
+++ sem_attr.adb	(working copy)
@@ -1015,6 +1015,16 @@ 
                  ("prefix for % attribute must be constrained array", P);
             end if;
 
+            --  The attribute reference freezes the type, and thus the
+            --  component type, even if the attribute may not depend on the
+            --  component. Diagnose arrays with incomplete components now.
+            --  If the prefix is an access to array, this does not freeze
+            --  the designated type.
+
+            if Nkind (P) /= N_Explicit_Dereference then
+               Check_Fully_Declared (Component_Type (P_Type), P);
+            end if;
+
             D := Number_Dimensions (P_Type);
 
          else