Commit 8d9509fd by Ed Schonberg Committed by Arnaud Charlet

sem_attr.adb: (Analyze_Attribute...

2008-08-05  Ed Schonberg  <schonberg@adacore.com>

	* sem_attr.adb:
	(Analyze_Attribute, case 'Result): handle properly the case where some
	operand of the expression in a post-condition generates a transient
	block.

From-SVN: r138722
parent c144ca8d
...@@ -3767,8 +3767,8 @@ package body Sem_Attr is ...@@ -3767,8 +3767,8 @@ package body Sem_Attr is
------------ ------------
when Attribute_Result => Result : declare when Attribute_Result => Result : declare
CS : constant Entity_Id := Current_Scope; CS : Entity_Id := Current_Scope;
PS : constant Entity_Id := Scope (CS); PS : Entity_Id := Scope (CS);
begin begin
-- If the enclosing subprogram is always inlined, the enclosing -- If the enclosing subprogram is always inlined, the enclosing
...@@ -3808,44 +3808,61 @@ package body Sem_Attr is ...@@ -3808,44 +3808,61 @@ package body Sem_Attr is
end if; end if;
-- Body case, where we must be inside a generated _Postcondition -- Body case, where we must be inside a generated _Postcondition
-- procedure, or the attribute use is definitely misplaced. -- procedure, and the prefix must be on the scope stack, or else
-- the attribute use is definitely misplaced. The condition itself
-- may have generated transient scopes, and is not necessarily the
-- current one.
elsif Chars (CS) = Name_uPostconditions else
and then Ekind (PS) = E_Function while Present (CS)
then and then CS /= Standard_Standard
-- Check OK prefix loop
if Chars (CS) = Name_uPostconditions then
exit;
else
CS := Scope (CS);
end if;
end loop;
if (Nkind (P) = N_Identifier PS := Scope (CS);
or else Nkind (P) = N_Operator_Symbol)
and then Chars (P) = Chars (PS) if Chars (CS) = Name_uPostconditions
and then Ekind (PS) = E_Function
then then
null; -- Check OK prefix
-- Within an instance, the prefix designates the local renaming if (Nkind (P) = N_Identifier
-- of the original generic. or else Nkind (P) = N_Operator_Symbol)
and then Chars (P) = Chars (PS)
then
null;
elsif Is_Entity_Name (P) -- Within an instance, the prefix designates the local renaming
and then Ekind (Entity (P)) = E_Function -- of the original generic.
and then Present (Alias (Entity (P)))
and then Chars (Alias (Entity (P))) = Chars (PS)
then
null;
else elsif Is_Entity_Name (P)
Error_Msg_NE and then Ekind (Entity (P)) = E_Function
("incorrect prefix for % attribute, expected &", P, PS); and then Present (Alias (Entity (P)))
Error_Attr; and then Chars (Alias (Entity (P))) = Chars (PS)
end if; then
null;
Rewrite (N, else
Make_Identifier (Sloc (N), Error_Msg_NE
Chars => Name_uResult)); ("incorrect prefix for % attribute, expected &", P, PS);
Analyze_And_Resolve (N, Etype (PS)); Error_Attr;
end if;
else Rewrite (N,
Error_Attr Make_Identifier (Sloc (N),
("% attribute can only appear in function Postcondition pragma", Chars => Name_uResult));
P); Analyze_And_Resolve (N, Etype (PS));
else
Error_Attr
("% attribute can only appear" &
" in function Postcondition pragma", P);
end if;
end if; end if;
end Result; end Result;
...@@ -7542,6 +7559,19 @@ package body Sem_Attr is ...@@ -7542,6 +7559,19 @@ package body Sem_Attr is
Note_Possible_Modification (P, Sure => False); Note_Possible_Modification (P, Sure => False);
end if; end if;
-- The following comes from a query by Adam Beneschan, concerning
-- improper use of universal_access in equality tests involving
-- anonymous access types. Another good reason for 'Ref, but
-- for now disable the test, which breaks several filed tests.
if Ekind (Typ) = E_Anonymous_Access_Type
and then Nkind_In (Parent (N), N_Op_Eq, N_Op_Ne)
and then False
then
Error_Msg_N ("need unique type to resolve 'Access", N);
Error_Msg_N ("\qualify attribute with some access type", N);
end if;
if Is_Entity_Name (P) then if Is_Entity_Name (P) then
if Is_Overloaded (P) then if Is_Overloaded (P) then
Get_First_Interp (P, Index, It); Get_First_Interp (P, Index, It);
......
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