]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Ada] Correctly reject record aggregate using brackets
authorMarc Poulhiès <poulhies@adacore.com>
Mon, 31 Jan 2022 14:54:41 +0000 (15:54 +0100)
committerPierre-Marie de Rodat <derodat@adacore.com>
Wed, 11 May 2022 08:53:21 +0000 (08:53 +0000)
Ada 2022 bracket syntax is only allowed for arrays and containers, not
records. This change correctly rejects record aggregates using brackets
along with few cases of brackets being used instead of parentheses.

gcc/ada/

* libgnat/a-direct.adb (Start_Search_Internal): Use parentheses
for record aggregate.
* libgnat/a-stbubo.adb (Get_UTF_8): Likewise.
* libgnat/a-stbuun.adb (Get_UTF_8): Likewise.
* libgnat/a-stzbou.ads (Null_Bounded_Wide_Wide_String):
Likewise.
* libgnat/a-swmwco.ads (Lower_Case_Mapping, Basic_Mapping):
Likewise.
* libgnat/a-szmzco.ads (Lower_Case_Mapping, Basic_Mapping):
Likewise.
* libgnat/s-statxd.adb (Fields): Likewise.
* libgnat/s-stausa.adb (Initialize): Likewise.
* sem_aggr.adb (Resolve_Record_Aggregate): Reject aggregates
using brackets.

gcc/ada/libgnat/a-direct.adb
gcc/ada/libgnat/a-stbubo.adb
gcc/ada/libgnat/a-stbuun.adb
gcc/ada/libgnat/a-stzbou.ads
gcc/ada/libgnat/a-swmwco.ads
gcc/ada/libgnat/a-szmzco.ads
gcc/ada/libgnat/s-statxd.adb
gcc/ada/libgnat/s-stausa.adb
gcc/ada/sem_aggr.adb

index 4d7288ebe3a35aa58c43326e36182df81261dd09..2c07cc4a332b76cc54d8adb819c95da7ba659210 100644 (file)
@@ -1404,11 +1404,11 @@ package body Ada.Directories is
                   if Error /= 0 then
                      Search.State.Dir_Contents.Append
                        (Directory_Entry_Type'
-                          [Valid           => True,
+                          (Valid           => True,
                            Name            => To_Unbounded_String (File_Name),
                            Full_Name       => To_Unbounded_String (Path),
                            Attr_Error_Code => Error,
-                           others          => <>]);
+                           others          => <>));
 
                   --  Otherwise, if the file exists and matches the file kind
                   --  Filter, add the file to the search results. We capture
@@ -1445,14 +1445,14 @@ package body Ada.Directories is
                      if Found then
                         Search.State.Dir_Contents.Append
                           (Directory_Entry_Type'
-                             [Valid             => True,
+                             (Valid             => True,
                               Name              =>
                                 To_Unbounded_String (File_Name),
                               Full_Name         => To_Unbounded_String (Path),
                               Attr_Error_Code   => 0,
                               Kind              => Kind,
                               Modification_Time => Modification_Time (Path),
-                              Size              => Size]);
+                              Size              => Size));
                      end if;
                   end if;
                end;
index c1c73da6e12605410b07845e8d7d27266398514e..3e941b8952035aabc5d64528d66e376f42cb039d 100644 (file)
@@ -91,9 +91,9 @@ package body Ada.Strings.Text_Buffers.Bounded is
             --  forget to add corresponding assignment statement below.
             Dummy : array (1 .. 0) of Buffer_Type (0) :=
               [others =>
-                 [Max_Characters => 0, Chars => <>, Indentation => <>,
+                 (Max_Characters => 0, Chars => <>, Indentation => <>,
                   Indent_Pending => <>, UTF_8_Length => <>, UTF_8_Column => <>,
-                  All_7_Bits     => <>, All_8_Bits => <>, Truncated => <>]];
+                  All_7_Bits     => <>, All_8_Bits => <>, Truncated => <>)];
          begin
             Buffer.Indentation    := Defaulted.Indentation;
             Buffer.Indent_Pending := Defaulted.Indent_Pending;
index e9ea52839844a776b32eb152221d5de9e21f30d2..eabcad1b628a206908beecf9582865ecfd41661a 100644 (file)
@@ -104,9 +104,9 @@ package body Ada.Strings.Text_Buffers.Unbounded is
             --  forget to add corresponding assignment statement below.
             Dummy : array (1 .. 0) of Buffer_Type :=
               [others =>
-                 [Indentation  => <>, Indent_Pending => <>, UTF_8_Length => <>,
+                 (Indentation  => <>, Indent_Pending => <>, UTF_8_Length => <>,
                   UTF_8_Column => <>, All_7_Bits => <>, All_8_Bits => <>,
-                  List         => <>, Last_Used => <>]];
+                  List         => <>, Last_Used => <>)];
          begin
             Buffer.Indentation    := Defaulted.Indentation;
             Buffer.Indent_Pending := Defaulted.Indent_Pending;
index 73d52ddd1eda49e7e1c6f5e62bb27fa0f01fb09d..e316d66a7f2bc96f78d3e4548ab81e6d2d5db9f9 100644 (file)
@@ -493,11 +493,11 @@ package Ada.Strings.Wide_Wide_Bounded is
       --  the Wide_Wide_Superbounded package.
 
       Null_Bounded_Wide_Wide_String : constant Bounded_Wide_Wide_String :=
-                                   [Max_Length         => Max_Length,
+                                   (Max_Length         => Max_Length,
                                     Current_Length     => 0,
                                     Data               =>
                                       [1 .. Max_Length =>
-                                        Wide_Wide_Superbounded.Wide_Wide_NUL]];
+                                        Wide_Wide_Superbounded.Wide_Wide_NUL]);
 
       pragma Inline (To_Bounded_Wide_Wide_String);
 
index f58424aa623499700dcf5f0020ede82656e3fba5..af11630226c6a947895aeb3c65d72bb7568d1fe7 100644 (file)
@@ -181,7 +181,7 @@ private
       Character_Ranges'Unrestricted_Access);
 
    Lower_Case_Mapping : aliased constant Wide_Character_Mapping_Values :=
-     [Length => 56,
+     (Length => 56,
 
       Domain =>
         "ABCDEFGHIJKLMNOPQRSTUVWXYZ" &
@@ -247,14 +247,14 @@ private
          W.LC_U_Circumflex           &
          W.LC_U_Diaeresis            &
          W.LC_Y_Acute                &
-         W.LC_Icelandic_Thorn];
+         W.LC_Icelandic_Thorn);
 
    Lower_Case_Map : constant Wide_Character_Mapping :=
      (AF.Controlled with
       Map => Lower_Case_Mapping'Unrestricted_Access);
 
    Upper_Case_Mapping : aliased constant Wide_Character_Mapping_Values :=
-     [Length => 56,
+     (Length => 56,
 
       Domain =>
         "abcdefghijklmnopqrstuvwxyz" &
@@ -320,14 +320,14 @@ private
          W.UC_U_Circumflex           &
          W.UC_U_Diaeresis            &
          W.UC_Y_Acute                &
-         W.UC_Icelandic_Thorn];
+         W.UC_Icelandic_Thorn);
 
    Upper_Case_Map : constant Wide_Character_Mapping :=
      (AF.Controlled with
       Upper_Case_Mapping'Unrestricted_Access);
 
    Basic_Mapping : aliased constant Wide_Character_Mapping_Values :=
-     [Length => 55,
+     (Length => 55,
 
       Domain =>
         W.UC_A_Grave          &
@@ -441,7 +441,7 @@ private
         'u'        &  -- LC_U_Circumflex
         'u'        &  -- LC_U_Diaeresis
         'y'        &  -- LC_Y_Acute
-        'y'];         -- LC_Y_Diaeresis
+        'y');         -- LC_Y_Diaeresis
 
    Basic_Map : constant Wide_Character_Mapping :=
      (AF.Controlled with
index 4d6eece33e3fae867e11d4419d85748fbb0cb391..96d64b36058dd56727312593a8cbaa2ce3779613 100644 (file)
@@ -181,7 +181,7 @@ private
       Character_Ranges'Unrestricted_Access);
 
    Lower_Case_Mapping : aliased constant Wide_Wide_Character_Mapping_Values :=
-     [Length => 56,
+     (Length => 56,
 
       Domain =>
         "ABCDEFGHIJKLMNOPQRSTUVWXYZ" &
@@ -247,14 +247,14 @@ private
          W.LC_U_Circumflex           &
          W.LC_U_Diaeresis            &
          W.LC_Y_Acute                &
-         W.LC_Icelandic_Thorn];
+         W.LC_Icelandic_Thorn);
 
    Lower_Case_Map : constant Wide_Wide_Character_Mapping :=
      (AF.Controlled with
       Map => Lower_Case_Mapping'Unrestricted_Access);
 
    Upper_Case_Mapping : aliased constant Wide_Wide_Character_Mapping_Values :=
-     [Length => 56,
+     (Length => 56,
 
       Domain =>
         "abcdefghijklmnopqrstuvwxyz" &
@@ -320,14 +320,14 @@ private
          W.UC_U_Circumflex           &
          W.UC_U_Diaeresis            &
          W.UC_Y_Acute                &
-         W.UC_Icelandic_Thorn];
+         W.UC_Icelandic_Thorn);
 
    Upper_Case_Map : constant Wide_Wide_Character_Mapping :=
      (AF.Controlled with
       Upper_Case_Mapping'Unrestricted_Access);
 
    Basic_Mapping : aliased constant Wide_Wide_Character_Mapping_Values :=
-     [Length => 55,
+     (Length => 55,
 
       Domain =>
         W.UC_A_Grave          &
@@ -441,7 +441,7 @@ private
         'u'        &  -- LC_U_Circumflex
         'u'        &  -- LC_U_Diaeresis
         'y'        &  -- LC_Y_Acute
-        'y'];         -- LC_Y_Diaeresis
+        'y');         -- LC_Y_Diaeresis
 
    Basic_Map : constant Wide_Wide_Character_Mapping :=
      (AF.Controlled with
index e34bef176ca97e1656cc405640b49c07814f25de..55386133aa3b8cc759547dc5bd89a027747212ac 100644 (file)
@@ -76,36 +76,36 @@ package body System.Stream_Attributes.XDR is
 
                --  Single precision
 
-              [E_Size  => 8,
+              (E_Size  => 8,
                E_Bias  => 127,
                F_Size  => 23,
                E_Last  => 2 ** 8 - 1,
                F_Mask  => 16#7F#,                  --  2 ** 7 - 1,
                E_Bytes => 2,
                F_Bytes => 3,
-               F_Bits  => 23 mod US],
+               F_Bits  => 23 mod US),
 
                --  Double precision
 
-              [E_Size  => 11,
+              (E_Size  => 11,
                E_Bias  => 1023,
                F_Size  => 52,
                E_Last  => 2 ** 11 - 1,
                F_Mask  => 16#0F#,                  --  2 ** 4 - 1,
                E_Bytes => 2,
                F_Bytes => 7,
-               F_Bits  => 52 mod US],
+               F_Bits  => 52 mod US),
 
                --  Quadruple precision
 
-              [E_Size  => 15,
+              (E_Size  => 15,
                E_Bias  => 16383,
                F_Size  => 112,
                E_Last  => 2 ** 8 - 1,
                F_Mask  => 16#FF#,                  --  2 ** 8 - 1,
                E_Bytes => 2,
                F_Bytes => 14,
-               F_Bits  => 112 mod US]];
+               F_Bits  => 112 mod US)];
 
    --  The representation of all items requires a multiple of four bytes
    --  (or 32 bits) of data. The bytes are numbered 0 through n-1. The bytes
index 8c0acc420bde7f9a69c7e597eb96cd1fb97b17b0..d050eaaeca4705afda959ce297342de27f8a981a 100644 (file)
@@ -128,9 +128,9 @@ package body System.Stack_Usage is
       Result_Array := new Result_Array_Type (1 .. Buffer_Size);
       Result_Array.all :=
         [others =>
-           [Task_Name   => [others => ASCII.NUL],
+           (Task_Name   => [others => ASCII.NUL],
             Value       => 0,
-            Stack_Size  => 0]];
+            Stack_Size  => 0)];
 
       --  Set the Is_Enabled flag to true, so that the task wrapper knows that
       --  it has to handle dynamic stack analysis
index 60195d27fe9533811bf240ab5a98840f0c7a26f7..6e73aac4a108b35d09b046ce9ebc723458fa4642 100644 (file)
@@ -4896,6 +4896,15 @@ package body Sem_Aggr is
          return;
       end if;
 
+      --  A record aggregate can only use parentheses
+
+      if Nkind (N) = N_Aggregate
+        and then Is_Homogeneous_Aggregate (N)
+      then
+         Error_Msg_N ("record aggregate must use () and not '[']", N);
+         return;
+      end if;
+
       --  STEP 2: Verify aggregate structure
 
       Step_2 : declare