Version 1.5 of ais/ai-00197.txt

Unformatted version of ais/ai-00197.txt version 1.5
Other versions for file ais/ai-00197.txt

!standard 07.06 (21)          99-07-27 AI95-00197/03
!class binding interpretation 98-10-02
!status ARG approved 7-0-0 98-10-08
!status work item 98-10-02
!status received 98-03-27
!priority Medium
!difficulty Medium
!reference AI-00083
!subject Aggregate initialization of controlled subcomponents
When an object of a controlled type is created and initialized with an aggregate, whether explicitly as part of an object declaration or allocator, or implicitly as part of the default initialization of some containing object, the implementation must not create a separate anonymous object for the aggregate. It must create the value of the aggregate directly in the newly created object. There is no assignment from the anonymous object to the newly created object, so the Finalize and Adjust that would be done for that assignment are not done.
AI-83 imposes a requirement that in the case of a controlled object explicitly initialized by an aggregate, implementations must initialize the object in place, without using a separate temporary. Should this requirement also apply to default-initialized objects that have controlled subcomponents that are initialized by an aggregate? (Yes.)
(See summary.)
(See summary.)
AI-83 discusses the cases of using an aggregate to initialize controlled objects that are created by object declarations and allocators. It does not mention the case of controlled subcomponents of a default-initialized object where the subcomponent is initialized by an aggregate. The !summary and !recommendation in AI-83 specifically state that the requirement applies to objects "explicitly initialized with an aggregate", which could be interpreted as not applying to default-initialized subcomponents, though there's no reason why the requirement should not apply to them as well.
This AI amends AI-83 by making it clear that the requirement applies to all controlled objects initialized by an aggregate, whether explicitly, or implicitly as part of the default initialization of some containing object.
!ACATS test
See AI-00083 for testing of this ruling.

!section 7.6(21)
!subject Aggregates of a controlled type
!section 7.6
!reference AI95-00083/02
!reference RM95-7.6(21)
!from Gary Dismukes 97-07-11
!reference 1997-15794.a Gary Dismukes 1997-11-8>>

AI-83 requires that a controlled object initialized by an
aggregate be built in place, without the use of the canonical
temporary object.  It seems that this requirement should also
exist for cases involving controlled components with default
initialization given by an aggregate, but it's not clear from
the wording of the AI whether it's intended to apply to such

For example, building on the example in the AI:

    type Dyn_String is private;
    Null_String : constant Dyn_String;
    type Dyn_String is new Ada.Finalization.Controlled
      with record
      end record;
    procedure Finalize(X : in out Dyn_String);
    procedure Adjust(X : in out Dyn_String);

    type Rec_with_String is
        Str : Dyn_String := (Ada.Finalization.Controlled with ...);
      end record;

    RS : Rec_with_String;

Is it intended that the component RS.Str be initialized in place,
without the use of a separate temporary object to hold the value
of the aggregate?  The fact that the summary says "explicitly
initialized" makes it unclear to me whether the AI is intended
to apply to this case (although the end of the !recommendation
does state that the interpretation applies to all object creations).
The question is whether the component's default initialization
is properly considered to be an "explicit initialization" for
purposes of this AI.


Questions? Ask the ACAA Technical Agent