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).
This commit is contained in:
Steve Baird 2024-07-31 15:29:04 -07:00 committed by Marc Poulhiès
parent 480819c921
commit fc49ee592a
2 changed files with 25 additions and 0 deletions

View file

@ -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.

View file

@ -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;