Patchwork [Ada] Illegal prefix in array attributes

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


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 must yield: 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;

    type X is new Integer;    

end Foo;

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

2013-01-02  Ed Schonberg  <>

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


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);