aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@adacore.com>2024-10-28 11:58:55 +0100
committerMarc Poulhiès <dkm@gcc.gnu.org>2024-11-12 14:05:44 +0100
commit0362d7aa8fcdb63505a6b37a36fc7cc5845ba80c (patch)
treebf4690d983dc0b3655d2d859cff1032a2931ab79 /gcc
parent3408792e6016a53cbc10653948e07132d0f13361 (diff)
downloadgcc-0362d7aa8fcdb63505a6b37a36fc7cc5845ba80c.zip
gcc-0362d7aa8fcdb63505a6b37a36fc7cc5845ba80c.tar.gz
gcc-0362d7aa8fcdb63505a6b37a36fc7cc5845ba80c.tar.bz2
ada: Fix assertion failure on illegal use of aspect Type_Invariant
The illegal use is on a type derived from a formal private type, e.g.: generic type T is private; package G is type D is new T with Type_Invariant => True; end G; gcc/ada/ChangeLog: PR ada/113037 * sem_prag.adb (Analyze_Pragma) <Pragma_Invariant>: Reject types that are derived from formal private types.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ada/sem_prag.adb16
1 files changed, 12 insertions, 4 deletions
diff --git a/gcc/ada/sem_prag.adb b/gcc/ada/sem_prag.adb
index f4ae89f..ef90396 100644
--- a/gcc/ada/sem_prag.adb
+++ b/gcc/ada/sem_prag.adb
@@ -19773,18 +19773,26 @@ package body Sem_Prag is
-- 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.