]> git.ipfire.org Git - thirdparty/gcc.git/commit
ada: Capacity determination for container aggregate with container iterator
authorGary Dismukes <dismukes@adacore.com>
Wed, 2 Jul 2025 21:49:39 +0000 (21:49 +0000)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Tue, 22 Jul 2025 08:35:14 +0000 (10:35 +0200)
commit2bcb3683f3b468dae3cd586db95ceb234cf6c98f
tree74bf0e4711f023e292e2727c9ca9bc9e47d63f27
parent83219c97fabc1c0a8e0c42ad3d023706b8132827
ada: Capacity determination for container aggregate with container iterator

In the case of a container aggregate that has a container_element_association
given by an iterator_specification that iterates over a container object
(for example, "[for E of V => E]"), the compiler will now determine the
number of elements in the object and can use that in determining the capacity
value to be passed to the container type's Empty function when allocating
space for the aggregate object.  This implementation-dependent behavior
is allowed by RM22 4.3.5(40/5).

Prior to this enhancement, the compiler would generally use the Empty
function's default value for the Capacity parameter (a value of just
10 in the current implementation of the predefined containers), which
could easily lead to Capacity_Error being raised for the aggregate.

Note that this is only done for aggregates of container types coming
from instantiations of the predefined container generics, and not for
user-defined container types (due to the special knowledge the compiler
has of the availability of Length functions for the predefined types).
Also, it currently only applies when the object V being iterated over
is a simple object, and is not done for more complex cases, such as
when V is a function call.

gcc/ada/ChangeLog:

* exp_aggr.adb (Build_Size_Expr): Determine the length of a container
aggregate association in the case where it's an iteration over an
object of a container type coming from an instantiation of a predefined
container generic. Minor updates to existing comments.
gcc/ada/exp_aggr.adb