-- An invariant must apply to a private type, or appear in the
-- private part of a package spec and apply to a completion.
- -- a class-wide invariant can only appear on a private declaration
+ -- A class-wide invariant can only appear on a private declaration
-- or private extension, not a completion.
- -- A [class-wide] invariant may be associated a [limited] private
- -- type or a private extension.
+ -- A [class-wide] invariant may be associated with a [limited]
+ -- private type. We need to explicitly exclude types that are
+ -- derived from formal private types here.
elsif Ekind (Typ) in E_Limited_Private_Type
| E_Private_Type
- | E_Record_Type_With_Private
+ and then not (Is_Derived_Type (Typ)
+ and then Is_Generic_Type (Etype (Typ)))
then
null;
+ -- A [class-wide] invariant may be associated with a private
+ -- extension.
+
+ elsif Ekind (Typ) = E_Record_Type_With_Private then
+ null;
+
-- A non-class-wide invariant may be associated with the full view
-- of a [limited] private type or a private extension.