Routine Is_Object_Reference, which implements Ada RM 3.3(2) that says
"All of the following are objects: ..." was slightly diverging from the
exact wording of that rule and from the exact wording of AI05-0003,
which allows qualified expressions to be used as objects (provided that
their expression itself is an object).

This patch fixes this routine to precisely follow both the wording of
Ada RM 3.3(2), i.e. it recognizes aggregates as objects (as introduced
in Ada 95) and it literally implements the rule about qualified
expression (as introduced in Ada 2012).

Finally, it recognizes string literals that come from folded aggregates
as objects.

Tested on x86_64-pc-linux-gnu, committed on trunk

2020-06-16  Piotr Trojanek  <troja...@adacore.com>

gcc/ada/

        * sem_ch8.adb (Analyze_Object_Renaming): Remove trivially
        useless initialization of Is_Object_Reference.
        * sem_util.adb (Is_Object_Reference): Simplify detection of
        binary and unary operators; literally implement rules about
        aggregates and qualified expressions; recognize string literals
        as object references.
--- gcc/ada/sem_ch8.adb
+++ gcc/ada/sem_ch8.adb
@@ -754,7 +754,7 @@ package body Sem_Ch8 is
       Id            : constant Entity_Id  := Defining_Identifier (N);
       Loc           : constant Source_Ptr := Sloc (N);
       Nam           : constant Node_Id    := Name (N);
-      Is_Object_Ref : Boolean := False;
+      Is_Object_Ref : Boolean;
       Dec           : Node_Id;
       T             : Entity_Id;
       T2            : Entity_Id;
@@ -1366,7 +1366,7 @@ package body Sem_Ch8 is
       if T = Any_Type or else Etype (Nam) = Any_Type then
          return;
 
-      --  Verify that the renamed entity is an object or function call.
+      --  Verify that the renamed entity is an object or function call
 
       elsif Is_Object_Ref then
          if Comes_From_Source (N) then

--- gcc/ada/sem_util.adb
+++ gcc/ada/sem_util.adb
@@ -16978,9 +16978,8 @@ package body Sem_Util is
             --  Note that predefined operators are functions as well, and so
             --  are attributes that are (can be renamed as) functions.
 
-            when N_Binary_Op
-               | N_Function_Call
-               | N_Unary_Op
+            when N_Function_Call
+               | N_Op
             =>
                return Etype (N) /= Standard_Void_Type;
 
@@ -17040,12 +17039,21 @@ package body Sem_Util is
             --  of aggregates in more contexts.
 
             when N_Qualified_Expression =>
-               if Ada_Version <  Ada_2012 then
-                  return False;
-               else
-                  return Is_Object_Reference (Expression (N))
-                    or else Nkind (Expression (N)) = N_Aggregate;
-               end if;
+               return Ada_Version >= Ada_2012
+                 and then Is_Object_Reference (Expression (N));
+
+            --  In Ada 95 an aggreate is an object reference
+
+            when N_Aggregate =>
+               return Ada_Version >= Ada_95;
+
+            --  A string literal is not an object reference, but it might come
+            --  from rewriting of an object reference, e.g. from folding of an
+            --  aggregate.
+
+            when N_String_Literal =>
+               return Is_Rewrite_Substitution (N)
+                 and then Is_Object_Reference (Original_Node (N));
 
             when others =>
                return False;

Reply via email to