]> git.ipfire.org Git - thirdparty/gcc.git/commit
ada: Errors on instance of Multiway_Trees with discriminated type
authorGary Dismukes <dismukes@adacore.com>
Wed, 15 Nov 2023 23:57:47 +0000 (23:57 +0000)
committerMarc Poulhiès <poulhies@adacore.com>
Tue, 28 Nov 2023 09:35:48 +0000 (10:35 +0100)
commit1a2f4e332c0bca0b6665921c38be9c9f1c04e0b4
tree80ecb5bdbd4d77f9733b34cde9c822b994414098
parentecdcb83025143f00e95ce9f86b9e80c770116c46
ada: Errors on instance of Multiway_Trees with discriminated type

The compiler may report various type conflicts on an instantiation
of the generic package Ada.Containers.Multiway_Trees with an actual
for Element_Type that is a nonprivate actual type with discriminants
that has a discriminant-dependent component of a private type (such
as a Bounded_Vector type). The type errors occur on an aggregate
of the implementation type Tree_Node_Type within the body of
Multiway_Trees, where the aggregate has a box-defaulted association
for the Element component. (Such type errors could of course arise
in other cases of generic instantiations that follow a similar type
model.)

In the case where the discriminant-dependent component type has a
default-initialization procedure (init proc), the compiler was handling
box associations for such components by expanding the topmost box
association into subaggregates that themselves have box associations,
and didn't properly account for discriminant-dependent subcomponents of
private types. This could be fixed internally in Propagate_Discriminants,
but it seems that the entire machinery for dealing with such subcomponent
associations is unnecessary, and the topmost component association can
be handled directly as a default-initialized box association.

gcc/ada/

* sem_aggr.adb (Add_Discriminant_Values): Remove this procedure.
(Propagate_Discriminants): Remove this procedure.
(Resolve_Record_Aggregate): Remove code (the Capture_Discriminants
block statement) related to propagating discriminants and
generating initializations for subcomponents of a
discriminant-dependent box-defaulted subcomponent of a nonprivate
record type with discriminants, and handle all top-level
components that have a non-null base init proc directly, by
calling Add_Association with "Is_Box_Present => True". Also,
combine that elsif clause with the immediately preceding elsif
clause, since they now both contain the same statement (calls to
Add_Association with the same actuals).
gcc/ada/sem_aggr.adb