Compiler rejects an instantiation but accepts the corresponding generic
unit, when it includes a declaration for a private type whose full view
is a record type with a controlled component, and the full view of an
object of the type is given by an aggregate with default-initialized
components.
Tested on x86_64-pc-linux-gnu, committed on trunk
gcc/ada/
* sem_aggr.adb (Resolve_Record_Aggregate, Step_5): Do not check
for the need to use an extension aggregate for a given component
when within an instance and the type of the component hss a
private ancestor: the instantiation is legal if the generic
compiles, and spurious errors may be generated otherwise.
diff --git a/gcc/ada/sem_aggr.adb b/gcc/ada/sem_aggr.adb
--- a/gcc/ada/sem_aggr.adb
+++ b/gcc/ada/sem_aggr.adb
@@ -5028,12 +5028,19 @@ package body Sem_Aggr is
Prepend_Elmt (Parent_Typ, To => Parent_Typ_List);
Parent_Typ := Etype (Parent_Typ);
+ -- Check whether a private parent requires the use of
+ -- an extension aggregate. This test does not apply in
+ -- an instantiation: if the generic unit is legal so is
+ -- the instance.
+
if Nkind (Parent (Base_Type (Parent_Typ))) =
N_Private_Type_Declaration
or else Nkind (Parent (Base_Type (Parent_Typ))) =
N_Private_Extension_Declaration
then
- if Nkind (N) /= N_Extension_Aggregate then
+ if Nkind (N) /= N_Extension_Aggregate
+ and then not In_Instance
+ then
Error_Msg_NE
("type of aggregate has private ancestor&!",
N, Parent_Typ);