!standard 4.3(4/5)                                        23-03-23  AI22-0067-1/00

!class binding interpretation 23-03-23

!status work item 23-03-23

!status received 23-03-23

!priority Low

!difficulty Easy

!qualifier Omission

!subject The nominal subtype of an aggregate


The nominal subtype of an aggregate is defined.


3.3(23/5) starts "At the place where a view of an object is defined, a nominal

subtype is associated with the view." 4.3(5) states that an aggregate is a

view of an object. But nowhere do we define the nominal subtype of an



(See Summary.)


** TBD.

[The details of the definition are TBD. Most likely, the "nominal" subtype of an aggregate would be anonymous and be a constrained subtype with the bounds/discriminants of the aggregate. The rule would either go in static semantics for 4.3, or perhaps in each of the individual subclauses (which would separate the discriminant/bounds/container cases).]


Most of the rules that use the nominal subtype of an object don't apply to aggregates, at least for Ada 2012.

The only one we could find is rather obscure, involving inferable discriminants of an unchecked union (see B.3.3(20/2)). Thus checks involving aggregates of unchecked unions are ill-defined. For example:

with Ada.Text_IO;
procedure Unchecked_Union_No_Default_Test is

   type Precision is (Single_Precision, Multiple_Precision);

   type Number (Kind : Precision) is record
      case Kind is
         when Single_Precision   =>
            SP_Value : Long_Float;
         when Multiple_Precision =>
            MP_Value_Length : Integer;
            MP_Value_First  : access Long_Float;
      end case;
   end record
      with Unchecked_Union;

   Y : Number (Single_Precision); -- Inferable discriminant
   Y.SP_Value := 55.7;
   if Y = (Single_Precision, 45.6) then -- (1)
      Ada.Text_IO.Put_Line ("Y is single 45.6");
      Ada.Text_IO.Put_Line ("Y isn't single 45.6");
   end if;
end Unchecked_Union_No_Default_Test;


To determine whether (1) raises Program_Error by B.3.3(23/2):

Evaluation of the predefined equality operator for an unchecked union type if either of the operands lacks inferable discriminants.

we need to know if the aggregate has inferable discriminants, and to answer that question, we need to know the nominal subtype of the aggregate. And we really don't want (1) raising Program_Error, since the discriminants involved are known and static.

So we could fix both of the identified problems by specific rules; carving out an exception to the general rule that objects have a nominal subtype, and adding a specific rule about aggregates that are unchecked unions.

However, we have a number of proposals for composite case statements in the pipeline. Assuming that coverage would work the same for those as it does for discrete subtypes, the nominal subtype would become much more important. And it would not be surprising to find/create other cases where the nominal subtype is required.

As such, we recommend that the nominal subtype be defined, and it be defined as tightly as possible, so that the unchecked union case and the case statement case require only what is necessary. (Simply defining all aggregates as unconstrained would not be a good idea.)

!ACATS test

ACATS tests might be necessary to check that the appropriate effects occur.

The example given in the !discussion probably should be an ACATS C-Test,

for instance.


The original mail on this topic is filed in AI12-0066-1.