Comments

This change fixes two unrelated issues in the handling of references to
discriminants appearing in aggregates. If such a reference comes from
a default expression, it denotes a discriminal of the type of the aggregate,
and must be rewritten into a selected component prefixed by the entity
for the aggregate object. But if the reference is to a discriminal of some
other type (case of the aggregate being in a protected body), it must
be left untouched at this point.
When the rewriting does occur, it must use the Lhs parameter of
Build_Record_Aggregate_Code, not Obj, which is present only in the
variable declaration and dynamic allocation cases.
The following compilation must be accepted quietly:
$ gcc -c prot_discriminal_in_aggr.adb
with GNAT.Sockets;
package Prot_Discriminal_In_Aggr is
protected type Prot (Port_Num : GNAT.Sockets.Port_Type) is
private
The_Data : GNAT.Sockets.Sock_Addr_Type :=
(GNAT.Sockets.Family_Inet,
GNAT.Sockets.No_Inet_Addr,
Port_Num);
end Prot;
end Prot_Discriminal_In_Aggr;
package body Prot_Discriminal_In_Aggr is
protected body Prot is
end Prot;
end Prot_Discriminal_In_Aggr;
Tested on x86_64-pc-linux-gnu, committed on trunk
2010-06-22 Thomas Quinot <quinot@adacore.com>
* exp_aggr.adb (Rewrite_Discriminant): Rewriting must occur only for an
expression referring to a discriminal of the type of the aggregate (not
a discriminal of some other unrelated type), and the prefix in the
generated selected component must come from Lhs, not Obj.