aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Baird <baird@adacore.com>2024-07-31 15:29:04 -0700
committerMarc Poulhiès <dkm@gcc.gnu.org>2024-08-08 16:28:29 +0200
commitfc49ee592a9d72af458634f272e7dce26e7d65fd (patch)
tree108f88a008bea14c0befcef0b90d1f85ff8258d4
parent480819c921ed656ace16c5359aaa2d9abdc73ba5 (diff)
downloadgcc-fc49ee592a9d72af458634f272e7dce26e7d65fd.zip
gcc-fc49ee592a9d72af458634f272e7dce26e7d65fd.tar.gz
gcc-fc49ee592a9d72af458634f272e7dce26e7d65fd.tar.bz2
ada: Missing legality check when type completed
An access discriminant is allowed to have a default value only if the discriminated type is immutably limited. In the case of a discriminated limited private type declaration, this rule needs to be checked when the completion of the type is seen. gcc/ada/ * sem_ch6.adb (Check_Discriminant_Conformance): Perform check for illegal access discriminant default values when the completion of a limited private type is analyzed. * sem_aux.adb (Is_Immutably_Limited): If passed the not-yet-analyzed entity for the full view of a record type, test the Limited_Present flag (which is set by the parser).
-rw-r--r--gcc/ada/sem_aux.adb11
-rw-r--r--gcc/ada/sem_ch6.adb14
2 files changed, 25 insertions, 0 deletions
diff --git a/gcc/ada/sem_aux.adb b/gcc/ada/sem_aux.adb
index 0639a2e..9903a2b 100644
--- a/gcc/ada/sem_aux.adb
+++ b/gcc/ada/sem_aux.adb
@@ -1118,6 +1118,17 @@ package body Sem_Aux is
elsif Is_Private_Type (Btype) then
+ -- If Ent occurs in the completion of a limited private type, then
+ -- look for the word "limited" in the full view.
+
+ if Nkind (Parent (Ent)) = N_Full_Type_Declaration
+ and then Nkind (Type_Definition (Parent (Ent))) =
+ N_Record_Definition
+ and then Limited_Present (Type_Definition (Parent (Ent)))
+ then
+ return True;
+ end if;
+
-- AI05-0063: A type derived from a limited private formal type is
-- not immutably limited in a generic body.
diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb
index d3912ff..5735efb 100644
--- a/gcc/ada/sem_ch6.adb
+++ b/gcc/ada/sem_ch6.adb
@@ -6456,6 +6456,20 @@ package body Sem_Ch6 is
New_Discr_Id);
return;
end if;
+
+ if NewD
+ and then Ada_Version >= Ada_2005
+ and then Nkind (Discriminant_Type (New_Discr)) =
+ N_Access_Definition
+ and then not Is_Immutably_Limited_Type
+ (Defining_Identifier (N))
+ then
+ Error_Msg_N
+ ("(Ada 2005) default value for access discriminant "
+ & "requires immutably limited type",
+ Expression (New_Discr));
+ return;
+ end if;
end if;
end;