-
- Downloads
ada: Excess elements created for indexed aggregates with iterator_specifications
In the case of an indexed aggregate of a container type with both Add_Unnamed and New_Indexed specified in the Aggregate aspect of the type (such as for the Vector type in Ada.Containers.Vectors), in cases where a component association is given by an iterator_specification, the compiler could end up generating a call to the New_Indexed operation rather than the Empty operation. For example, in the case of a Vector type, this could result in allocating a container of the size of the defaulted Capacity formal of the New_Vector function (with uninitialized components), and elements added in the aggregate would append to that preallocated Vector. The compiler is corrected so that the Empty function is called to initialize the implicit aggregate object, rather than the New_Indexed function. gcc/ada/ * exp_aggr.adb (Expand_Container_Aggregate): Add code to determine whether the aggregate is an indexed aggregate, setting a flag (Is_Indexed_Aggregate), which is tested to have proper separation of treatment for the Add_Unnamed (for positional aggregates) and New_Indexed (for indexed aggregates) cases. In the code generating associations for indexed aggregates, remove the code for Expressions cases entirely, since the code for indexed aggregates is governed by the presence of Component_Associations, and add an assertion that Expressions must be Empty. Also, exclude empty aggregates from entering that code.
Loading
Please register or sign in to comment