AI12-0124 adds the notation Object'Image to the language, following the
semantics of GNAT-defined attribute 'Img. This patch fixes an omission in
the characterization of objects, which must include function calls and thus
attribute references for attributes that are functions, as well as predefined
operators.
The following must compile and execute quietly:
gnatmake -q img
img
---
procedure Img is
type Enum is (A, BC, ABC, A_B_C, abcd, 'd');
type New_Enum is new Enum;
function Ident (X : Enum) return Enum is
begin
return X;
end Ident;
E1 : New_Enum := New_Enum (Ident (BC));
type Int is new Long_Integer;
type Der is new Int;
function Ident (X : Der) return Der is
begin
return X;
end Ident;
V : Der := Ident (123);
begin
if New_Enum'Pred (E1)'Img /= "A" then
raise Program_Error;
end if;
if New_Enum'Pred (E1)'Image /= "A" then
raise Program_Error;
end if;
if Der'(V - 23)'Image /= "100" then
raise Program_Error;
end if;
end;
Tested on x86_64-pc-linux-gnu, committed on trunk
2017-09-06 Ed Schonberg <[email protected]>
* sem_util.adb (Is_Object_Reference): A function call is an
object reference, and thus attribute references for attributes
that are functions (such as Pred and Succ) as well as predefined
operators are legal in contexts that require an object, such as
the prefix of attribute Img and the Ada2020 version of 'Image.
Index: sem_util.adb
===================================================================
--- sem_util.adb (revision 251753)
+++ sem_util.adb (working copy)
@@ -14153,18 +14153,21 @@
-- In Ada 95, a function call is a constant object; a procedure
-- call is not.
- when N_Function_Call =>
+ -- Note that predefined operators are functions as well, and so
+ -- are attributes that are (can be renamed as) functions.
+
+ when N_Function_Call | N_Binary_Op | N_Unary_Op =>
return Etype (N) /= Standard_Void_Type;
- -- Attributes 'Input, 'Loop_Entry, 'Old, and 'Result produce
- -- objects.
+ -- Attributes references 'Loop_Entry, 'Old, and 'Result yield
+ -- objects, even though they are not functions.
when N_Attribute_Reference =>
return
- Nam_In (Attribute_Name (N), Name_Input,
- Name_Loop_Entry,
+ Nam_In (Attribute_Name (N), Name_Loop_Entry,
Name_Old,
- Name_Result);
+ Name_Result)
+ or else Is_Function_Attribute_Name (Attribute_Name (N));
when N_Selected_Component =>
return