A subtype is created from the renamed object in an object renaming declaration with an unconstrained nominal subtype. That subtype must be frozen ahead of the renaming declaration, to prevent order of elaboration issues when the nominal subtype of the object has unknown discriminants. The renamed object itself has already frozen the type.
The following must compile quietly in ada 2012 mode: with Q; procedure P is subtype Name is String with Dynamic_Predicate => (for all C of Name => C not in 'a'..'z'); package My_Q is new Q (Name); begin null; end; --- generic type Key_Type (<>) is private; package Q is type Key_Access is access Key_Type; type Cursor is record Key : Key_Access; end record; procedure Query_Element (Position : Cursor); end Q; --- package body Q is procedure Query_Element (Position : Cursor) is K : Key_Type renames Position.Key.all; begin null; end; end Q; Tested on x86_64-pc-linux-gnu, committed on trunk 2013-04-11 Ed Schonberg <schonb...@adacore.com> * sem_ch8.adb (Check_Constrained_Object): If a subtype is created from the renamed object in an object renaming declaration with an unconstrained nominal subtype, freeze the created subtype at once, to prevent order of elaboration issues in the backend.
Index: sem_ch8.adb =================================================================== --- sem_ch8.adb (revision 197746) +++ sem_ch8.adb (working copy) @@ -792,6 +792,12 @@ Make_Subtype_From_Expr (Nam, Typ))); Rewrite (Subtype_Mark (N), New_Occurrence_Of (Subt, Loc)); Set_Etype (Nam, Subt); + + -- Freeze subtype at once, to prevent order of elaboration + -- issues in the backend. The renamed object exists, so its + -- type is already frozen in any case. + + Freeze_Before (N, Subt); end if; end if; end Check_Constrained_Object;