This patch corrects the creation of equivalent class-wide types for records with unknown discriminants. Equivalent class-wide types are used by the back end to determine the size of an object. As a result it is now possible to deallocate a class-wide object whose root base type has unknown discriminants.
Tested on x86_64-pc-linux-gnu, committed on trunk 2011-11-23 Hristian Kirtchev <kirtc...@adacore.com> * exp_intr.adb (Expand_Unc_Deallocation): Ensure that the dereference has a proper type before the side effect removal mechanism kicks in. * sem_ch3.adb (Analyze_Subtype_Declaration): Handle a rare case where the base type of the subtype is a private itype created to act as the partial view of a constrained record type. This scenario manifests with equivalent class-wide types for records with unknown discriminants.
Index: sem_ch3.adb =================================================================== --- sem_ch3.adb (revision 181662) +++ sem_ch3.adb (working copy) @@ -4064,6 +4064,19 @@ T := Process_Subtype (Subtype_Indication (N), N, Id, 'P'); + -- Class-wide equivalent types of records with unknown discriminants + -- involve the generation of an itype which serves as the private view + -- of a constrained record subtype. In such cases the base type of the + -- current subtype we are processing is the private itype. Use the full + -- of the private itype when decorating various attributes. + + if Is_Itype (T) + and then Is_Private_Type (T) + and then Present (Full_View (T)) + then + T := Full_View (T); + end if; + -- Inherit common attributes Set_Is_Generic_Type (Id, Is_Generic_Type (Base_Type (T))); Index: exp_intr.adb =================================================================== --- exp_intr.adb (revision 181662) +++ exp_intr.adb (working copy) @@ -1123,6 +1123,10 @@ D_Type : Entity_Id; begin + -- Perform minor decoration as it is needed by the side effect + -- removal mechanism. + + Set_Etype (Deref, Desig_T); Set_Parent (Deref, Free_Node); D_Subtyp := Make_Subtype_From_Expr (Deref, Desig_T);