Rationale for Ada 2012
There is one minor change in this area which was
mentioned in the Introduction.
In Ada 2005, a discriminant can only have a default
if it is not tagged. But in Ada 2012, a default is also permitted in
the case of a limited tagged type.
Ada typically uses defaults as a convenience so that
in many cases standard information can be omitted. Thus it is convenient
that the procedure New_Line has a default
of 1 since it would be boring to have to write New_Line(1);all
In the case of discriminants
however, a default as in
type Polynomial(N: Index := 0) is
A: Integer_Vector(0 .. N);
also indicates that the type is mutable.
This means that the value of the discriminant of an object of the type
can be changed by a whole record assignment. However, tagged types in
Ada 2005 never have defaults because we do not want tagged types to be
mutable. On the other hand if a tagged type is limited then it is immutable
anyway. And so it was concluded that there is no harm in permitting a
limited tagged type to have a default discriminant.
This may seem rather
academic but the problem arose in designing containers for queues. It
was felt desirable that the protected type Queue
should have a discriminant giving its ceiling priority and that this
should have a default for convenience. As illustrated in the Introduction
this resulted in a structure as follows
with package Queue_Interfaces is new ...
Default_Ceiling: Any_Priority := Priority'Last;
package AC.Unbounded_Synchronized_Queues is
protected type Queue(Ceiling: Any_Priority := Default_Ceiling)
with Priority => Ceiling
is new Queue_Interfaces.Queue with ...
Now the problem is that a protected type such as
Queue which is derived from an interface is
considered to be tagged because interfaces are tagged. On the other hand
a protected type is always limited and its discriminant provides a convenient
way of providing the ceiling priority. So there was a genuine need for
a change to the rule.
Note incidentally that the default is itself provided
with the default value of Priority'Last since
it is a generic parameter with its own default.
© 2011, 2012, 2013 John Barnes Informatics.
Sponsored in part by: