The prefix of the Library_Level must now be an entity name, and the attribute indicates if the entity is declarated at the library level. Note that within a generic instantition, the name of the generic unit denotes the instance, which means that this attribute can be used to test if a generic is instantiated at the library level, as in:
1. generic 2. package LLTestP is 3. pragma Compile_Time_Warning 4. (not LLTestP'Library_Level, 5. "LLTest should be instantiated at library level"); 6. end; 1. with LLTestP; 2. package LLTestP1 is 3. package P is new LLTestP; 4. XXX : Integer; 5. P1L : constant Boolean := XXX'Library_Level; 6. end; 1. with LLTestP; 2. with LLTestP1; use LLTestP1; 3. with Text_IO; use Text_IO; 4. procedure LLTest is 5. package P1 is new LLTestP; | >>> warning: in instantiation at lltestp.ads:4 >>> warning: LLTest should be instantiated at library level 6. X : Integer; | >>> warning: variable "X" is read but never assigned 7. begin 8. Put_Line (Boolean'Image (LLTest'Library_Level)); 9. Put_Line (Boolean'Image (P1L)); 10. Put_Line (Boolean'Image (X'Library_Level)); 11. end; When executed, the output is: TRUE TRUE FALSE Tested on x86_64-pc-linux-gnu, committed on trunk 2013-10-14 Robert Dewar <de...@adacore.com> * gnat_rm.texi: Library_Level attribute now applies to an entity name. * sem_attr.adb (Analyze_Attribute, case Library_Level): Prefix is now an entity name.
Index: gnat_rm.texi =================================================================== --- gnat_rm.texi (revision 203528) +++ gnat_rm.texi (working copy) @@ -8348,21 +8348,20 @@ @findex Library_Level @noindent @noindent -@code{Standard'Library_Level} (@code{Standard} is the only allowed -prefix) returns a Boolean value which is True if the attribute is -evaluated at the library level (e.g. with a package declaration), -and false if evaluated elsewhere (e.g. within a subprogram body). -In the case of generics, the value indicates the placement of -the instantiation, not the template, and indeed the use of this -attribute within a generic is the intended common application -as shown in this example: +@code{P'Library_Level}, where P is an entity name, +returns a Boolean value which is True if the entity is declared +at the library level, and False otherwise. Note that within a +generic instantition, the name of the generic unit denotes the +instance, which means that this attribute can be used to test +if a generic is instantiated at the library level, as shown +in this example: @smallexample @c ada generic ... package Gen is pragma Compile_Time_Error - (not Standard'Library_Level, + (not Gen'Library_Level, "Gen can only be instantiated at library level"); ... end Gen; Index: sem_attr.adb =================================================================== --- sem_attr.adb (revision 203528) +++ sem_attr.adb (working copy) @@ -3689,11 +3689,14 @@ when Attribute_Library_Level => Check_E0; - Check_Standard_Prefix; + if not Is_Entity_Name (P) then + Error_Attr_P ("prefix of % attribute must be an entity name"); + end if; + if not Inside_A_Generic then Set_Boolean_Result (N, - Nearest_Dynamic_Scope (Current_Scope) = Standard_Standard); + Is_Library_Level_Entity (Entity (P))); end if; Set_Etype (N, Standard_Boolean);