[Ada] New No_Local_Tagged_Types restriction

Add new configuration restriction No_Local_Tagged_Types. This new
restriction ensures at compile time that all tagged types are only
declared at the library level.

gcc/ada/

	* libgnat/s-rident.ads (Restriction_Id): Add
	No_Local_Tagged_Types, update comment for adding new GNAT
	specific restriction.
	* restrict.ads (Implementation_Restriction): Add
	No_Local_Tagged_Types.
	* sem_ch3.adb (Analyze_Full_Type_Declaration): Add check for
	tagged type at library level.
	* doc/gnat_rm/standard_and_implementation_defined_restrictions.rst:
	Add No_Local_Tagged_Types description.
	* gnat_rm.texi: Regenerate.
This commit is contained in:
Marc Poulhiès 2022-02-01 12:20:51 +01:00 committed by Pierre-Marie de Rodat
parent c63b798f88
commit 4cfd39b0ff
5 changed files with 425 additions and 395 deletions

View file

@ -492,6 +492,13 @@ No_Local_Protected_Objects
[RM D.7] This restriction ensures at compile time that protected objects are
only declared at the library level.
No_Local_Tagged_Types
---------------------
.. index:: No_Local_Tagged_Types
[GNAT] This restriction ensures at compile time that tagged types are only
declared at the library level.
No_Local_Timing_Events
----------------------
.. index:: No_Local_Timing_Events

File diff suppressed because it is too large Load diff

View file

@ -81,7 +81,8 @@ package System.Rident is
-- To add a new restriction identifier, add an entry with the name to be
-- used in the pragma, and add calls to the Restrict.Check_Restriction
-- routine as appropriate.
-- routine as appropriate. If the new restriction is GNAT specific, also
-- add an entry in Restrict.Implementation_Restriction (restrict.ads).
type Restriction_Id is
@ -126,6 +127,7 @@ package System.Rident is
No_Implicit_Task_Allocations, -- GNAT
No_Implicit_Protected_Object_Allocations, -- GNAT
No_Initialize_Scalars, -- GNAT
No_Local_Tagged_Types, -- GNAT
No_Local_Allocators, -- (RM H.4(8))
No_Local_Timing_Events, -- (RM D.7(10.2/2))
No_Local_Protected_Objects, -- Ada 2012 (D.7(10/1.3))

View file

@ -131,6 +131,7 @@ package Restrict is
No_Implicit_Protected_Object_Allocations => True,
No_Implicit_Task_Allocations => True,
No_Initialize_Scalars => True,
No_Local_Tagged_Types => True,
No_Long_Long_Integers => True,
No_Multiple_Elaboration => True,
No_Secondary_Stack => True,

View file

@ -3479,6 +3479,14 @@ package body Sem_Ch3 is
then
Check_Nonoverridable_Aspects;
end if;
-- Check for tagged type declaration at library level
if Is_Tagged_Type (T)
and then not Is_Library_Level_Entity (T)
then
Check_Restriction (No_Local_Tagged_Types, T);
end if;
end Analyze_Full_Type_Declaration;
----------------------------------