From: Ronan Desplanques <desplanq...@adacore.com>

This patch fixes a bug where GNAT would emit incorrect warnings
about obsolescent syntax for array aggregates with generics and
particular arrangements of Ada version pragmas.

This patch also removes a syntactic field that was introduced to
support the emission of this warning, but is no longer required.

gcc/ada/

        * exp_imgv.adb (Append_Table_To): Remove reference to removed
        field.
        * gen_il-fields.ads: Remove Is_Enum_Array_Aggregate field.
        * gen_il-gen-gen_nodes.adb: Likewise.
        * sem_aggr.adb: Tweak warning emission condition.
        * sinfo.ads: Remove documentation for Is_Enum_Array_Aggregate.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/exp_imgv.adb             |  3 +--
 gcc/ada/gen_il-fields.ads        |  1 -
 gcc/ada/gen_il-gen-gen_nodes.adb |  1 -
 gcc/ada/sem_aggr.adb             | 13 ++++++++++++-
 gcc/ada/sinfo.ads                |  5 -----
 5 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/gcc/ada/exp_imgv.adb b/gcc/ada/exp_imgv.adb
index ec0126a7da2..6dc59f2c6f3 100644
--- a/gcc/ada/exp_imgv.adb
+++ b/gcc/ada/exp_imgv.adb
@@ -159,8 +159,7 @@ package body Exp_Imgv is
                    Make_Component_Definition (Loc,
                      Aliased_Present    => False,
                      Subtype_Indication => New_Occurrence_Of (Ctyp, Loc))),
-             Expression          => Make_Aggregate (Loc, Expressions => V,
-                                      Is_Enum_Array_Aggregate => True)));
+             Expression          => Make_Aggregate (Loc, Expressions => V)));
       end Append_Table_To;
 
    --  Start of Build_Enumeration_Image_Tables
diff --git a/gcc/ada/gen_il-fields.ads b/gcc/ada/gen_il-fields.ads
index cdd9b9577e2..7cf6a38faa3 100644
--- a/gcc/ada/gen_il-fields.ads
+++ b/gcc/ada/gen_il-fields.ads
@@ -259,7 +259,6 @@ package Gen_IL.Fields is
       Is_Generic_Contract_Pragma,
       Is_Homogeneous_Aggregate,
       Is_Parenthesis_Aggregate,
-      Is_Enum_Array_Aggregate,
       Is_Ignored,
       Is_Ignored_Ghost_Pragma,
       Is_In_Discriminant_Check,
diff --git a/gcc/ada/gen_il-gen-gen_nodes.adb b/gcc/ada/gen_il-gen-gen_nodes.adb
index 72280025498..d7cc39bc048 100644
--- a/gcc/ada/gen_il-gen-gen_nodes.adb
+++ b/gcc/ada/gen_il-gen-gen_nodes.adb
@@ -492,7 +492,6 @@ begin -- Gen_IL.Gen.Gen_Nodes
         Sy (Null_Record_Present, Flag),
         Sy (Is_Parenthesis_Aggregate, Flag),
         Sy (Is_Homogeneous_Aggregate, Flag),
-        Sy (Is_Enum_Array_Aggregate, Flag),
         Sm (Aggregate_Bounds_Or_Ancestor_Type, Node_Id),
         Sm (Entity_Or_Associated_Node, Node_Id), -- just Associated_Node
         Sm (Compile_Time_Known_Aggregate, Flag),
diff --git a/gcc/ada/sem_aggr.adb b/gcc/ada/sem_aggr.adb
index e381af101c8..508c86bc5de 100644
--- a/gcc/ada/sem_aggr.adb
+++ b/gcc/ada/sem_aggr.adb
@@ -2099,14 +2099,25 @@ package body Sem_Aggr is
 
       --  Disable the warning for GNAT Mode to allow for easier transition.
 
+      --  We don't warn about obsolescent usage of parentheses in generic
+      --  instances for two reasons:
+      --
+      --  1. An equivalent warning has been emitted in the corresponding
+      --     definition.
+      --  2. In cases where a generic definition specifies a version older than
+      --     Ada 2022 through a pragma and rightfully uses parentheses for
+      --     an array aggregate, an incorrect warning would be raised in
+      --     instances of that generic that are in Ada 2022 or later if we
+      --     didn't filter out the instance case.
+
       if Ada_Version_Explicit >= Ada_2022
         and then Warn_On_Obsolescent_Feature
         and then not GNAT_Mode
         and then not Is_Homogeneous_Aggregate (N)
-        and then not Is_Enum_Array_Aggregate (N)
         and then Is_Parenthesis_Aggregate (N)
         and then Nkind (Parent (N)) /= N_Qualified_Expression
         and then Comes_From_Source (N)
+        and then not In_Instance
       then
          Error_Msg_N
            ("?j?array aggregate using () is an" &
diff --git a/gcc/ada/sinfo.ads b/gcc/ada/sinfo.ads
index 803f5dfc759..4e977152cd0 100644
--- a/gcc/ada/sinfo.ads
+++ b/gcc/ada/sinfo.ads
@@ -1715,10 +1715,6 @@ package Sinfo is
    --    nodes which emulate the barrier function of a protected entry body.
    --    The flag is used when checking for incorrect use of Current_Task.
 
-   --  Is_Enum_Array_Aggregate
-   --    A flag set on an aggregate created internally while building the
-   --    images tables for enumerations.
-
    --  Is_Expanded_Build_In_Place_Call
    --    This flag is set in an N_Function_Call node to indicate that the extra
    --    actuals to support a build-in-place style of call have been added to
@@ -4091,7 +4087,6 @@ package Sinfo is
       --  Compile_Time_Known_Aggregate
       --  Expansion_Delayed
       --  Has_Self_Reference
-      --  Is_Enum_Array_Aggregate
       --  Is_Homogeneous_Aggregate
       --  Is_Parenthesis_Aggregate
       --  plus fields for expression
-- 
2.43.2

Reply via email to