This patch properly analyses aspects in cases when scopes differ such as
protected types, tasks, etc.
The test illustrates the analysis of aspects at freeze point specified for a
protected object.
------------
-- Source --
------------
package T is
type Typ is new Integer with Size => 128;
protected type Prot with Lock_Free => True is
procedure Reset;
private
Counter : Typ := 0;
end Prot;
end T;
package body T is
protected body Prot is
procedure Reset is
begin
Counter := 0;
end Reset;
end Prot;
end T;
-----------------
-- Compilation --
-----------------
$ gnatmake -q -gnat12 t.adb
t.adb:3:07: illegal body when Lock_Free given
t.adb:5:10: type of "Counter" must support atomic operations
gnatmake: "t.adb" compilation error
Tested on x86_64-pc-linux-gnu, committed on trunk
2012-08-06 Vincent Pucci <[email protected]>
* sem_ch13.adb: Current scope must be within
or same as the scope of the entity while analysing aspect
specifications at freeze point.
Index: sem_ch13.adb
===================================================================
--- sem_ch13.adb (revision 190155)
+++ sem_ch13.adb (working copy)
@@ -856,10 +856,11 @@
-- Start of processing for Analyze_Aspects_At_Freeze_Point
begin
- -- Must be declared in current scope. This is need for a generic
- -- context.
+ -- Must be visible in current scope. Note that this is needed for
+ -- entities that creates their own scope such as protected objects,
+ -- tasks, etc.
- if Scope (E) /= Current_Scope then
+ if not Scope_Within_Or_Same (Current_Scope, Scope (E)) then
return;
end if;
@@ -2434,11 +2435,12 @@
return;
-- Must be declared in current scope or in case of an aspect
- -- specification, must be the current scope.
+ -- specification, must be visible in current scope.
elsif Scope (Ent) /= Current_Scope
- and then (not From_Aspect_Specification (N)
- or else Ent /= Current_Scope)
+ and then
+ not (From_Aspect_Specification (N)
+ and then Scope_Within_Or_Same (Current_Scope, Scope (Ent)))
then
Error_Msg_N ("entity must be declared in this scope", Nam);
return;