Commit cec29135 by Ed Schonberg Committed by Arnaud Charlet

sem_ch3.adb (Access_Subprogram_Definition): Additional checks on illegal uses of…

sem_ch3.adb (Access_Subprogram_Definition): Additional checks on illegal uses of incomplete types in formal parts and...

2009-04-17  Ed Schonberg  <schonberg@adacore.com>

	* sem_ch3.adb (Access_Subprogram_Definition): Additional checks on
	illegal uses of incomplete types in formal parts and return types.

	* sem_ch6.adb (Process_Formals): Taft-amendment types are legal in
	access to subprograms.

	* sem_ch7.adb (Uninstall_Declarations): diagnose attempts to use
	Taft-amendment types as the return type of an access_to_function type.

	* freeze.adb (Freeze_Entity): Remove tests on formals of an incomplete
	type for access_to_subprograms. The check is performed on package exit.

From-SVN: r146229
parent 618fb570
......@@ -3497,50 +3497,11 @@ package body Freeze is
Freeze_Subprogram (E);
-- Ada 2005 (AI-326): Check wrong use of tag incomplete type
-- type T; -- tagged or untagged, may be from limited view
-- type Acc is access function (X : T) return T; -- ERROR
if Ekind (Etype (E)) = E_Incomplete_Type
and then No (Full_View (Etype (E)))
and then not Is_Value_Type (Etype (E))
then
Error_Msg_NE
("invalid use of incomplete type&", E, Etype (E));
end if;
-- For access to a protected subprogram, freeze the equivalent type
-- (however this is not set if we are not generating code or if this
-- is an anonymous type used just for resolution).
elsif Is_Access_Protected_Subprogram_Type (E) then
-- AI-326: Check wrong use of tagged incomplete types
-- type T is tagged;
-- type As3D is access protected
-- function (X : Float) return T; -- ERROR
declare
Etyp : Entity_Id;
begin
Etyp := Etype (Directly_Designated_Type (E));
if Is_Class_Wide_Type (Etyp) then
Etyp := Etype (Etyp);
end if;
if Ekind (Etyp) = E_Incomplete_Type
and then No (Full_View (Etyp))
and then not Is_Value_Type (Etype (E))
then
Error_Msg_NE
("invalid use of incomplete type&", E, Etyp);
end if;
end;
if Present (Equivalent_Type (E)) then
Freeze_And_Append (Equivalent_Type (E), Loc, Result);
end if;
......
......@@ -1135,7 +1135,27 @@ package body Sem_Ch3 is
(T => Typ,
Related_Nod => T_Def,
Scope_Id => Current_Scope));
else
if From_With_Type (Typ) then
Error_Msg_NE
("illegal use of incomplete type&",
Result_Definition (T_Def), Typ);
elsif Ekind (Current_Scope) = E_Package
and then In_Private_Part (Current_Scope)
then
if Ekind (Typ) = E_Incomplete_Type then
Append_Elmt (Desig_Type, Private_Dependents (Typ));
elsif Is_Class_Wide_Type (Typ)
and then Ekind (Etype (Typ)) = E_Incomplete_Type
then
Append_Elmt
(Desig_Type, Private_Dependents (Etype (Typ)));
end if;
end if;
Set_Etype (Desig_Type, Typ);
end if;
end;
......
......@@ -7716,7 +7716,8 @@ package body Sem_Ch6 is
-- primitive operations, as long as their completion is
-- in the same declarative part. If in the private part
-- this means that the type cannot be a Taft-amendment type.
-- Check is done on package exit.
-- Check is done on package exit. For access to subprograms,
-- the use is legal for Taft-amendment types.
if Is_Tagged_Type (Formal_Type) then
if Ekind (Scope (Current_Scope)) = E_Package
......@@ -7724,9 +7725,14 @@ package body Sem_Ch6 is
and then not From_With_Type (Formal_Type)
and then not Is_Class_Wide_Type (Formal_Type)
then
Append_Elmt
(Current_Scope,
Private_Dependents (Base_Type (Formal_Type)));
if not Nkind_In
(Parent (T), N_Access_Function_Definition,
N_Access_Procedure_Definition)
then
Append_Elmt
(Current_Scope,
Private_Dependents (Base_Type (Formal_Type)));
end if;
end if;
-- Special handling of Value_Type for CIL case
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment