-- RM 3.7(11)
-- No default expressions are permitted in a known_discriminant_part
-- in a declaration of a tagged type or a generic formal type.
package Test_244943 is
type T (n: Natural := 10) is private;
type T (n: Natural := 10) is tagged -- ERROR: no default allowed
The compiler says nothing; I was expecting something like:
test_244943:7:22: no default value allowed for discriminant N
are you sure that this applies when a tagged type is used as a completion of a private type with discriminants having default expressions?
This case is handled specially in GNAT sources. sem_ch3.adb reads:
-- Tagged types cannot have defaulted discriminants, but a
-- non-tagged private type with defaulted discriminants
-- can have a tagged completion.
7.3(15) says that a private type has a partial view and a full view, and the properties of the partial view apply in some places, and the properties of the full view apply in other places. So in places where the full view applies, the type is considered tagged, and cannot have default expressions in the known_discriminant part.
You seem to imply that the full view does not apply in the completion of the type, as the full view does not even exist yet. Taking the RM literally, you may be right but the annotated AARM 3.7(11.b/2) provides guidance:
Defaults for discriminants of tagged types are disallowed so that
every object of a tagged type is constrained, either by an explicit
constraint, or by its initial discriminant values. This substantially
simplifies the semantic rules and the implementation of inherited
dispatching operations. For generic formal types, the restriction
simplifies the type matching rules. If one simply wants a "default"
value for the discriminants, a constrained subtype can be declared for
I think this rule would be violated for objects of the type declared in the private part where the full view applies, i.e. you could declare unconstrained objects of the tagged type.
So, I confirm this to be a bug.
Confirmed on 4.3.0 20071213
Confirmed on 4.4.1.
Fixed in 4.6.1
$ gcc -c test_244943.ads
test_244943.ads:4:26: discriminants of tagged type cannot have defaults