]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Ada] Raise Capacity_Error on formal vector insertion
authorClaire Dross <dross@adacore.com>
Tue, 21 Jul 2020 15:37:23 +0000 (17:37 +0200)
committerPierre-Marie de Rodat <derodat@adacore.com>
Wed, 21 Oct 2020 07:22:43 +0000 (03:22 -0400)
gcc/ada/

* libgnat/a-cofove.adb (Copy): Add explanation in case of
Capacity_Error.
(Insert_Space): Raise Capacity_Error if the new length is
greater than the capacity.
(Reserve_Capacity): Raise Capacity_Error instead of
Constraint_Error.

gcc/ada/libgnat/a-cofove.adb

index c8a60df2a3ddd90646ec87e1bd7d3fd64278d18c..d467384f24205693c384f4c1f192f2d900b541cc 100644 (file)
@@ -171,7 +171,7 @@ is
       elsif Capacity >= LS then
          C := Capacity;
       else
-         raise Capacity_Error;
+         raise Capacity_Error with "Capacity too small";
       end if;
 
       return Target : Vector (C) do
@@ -956,6 +956,12 @@ is
 
       if New_Length > Max_Length then
          raise Constraint_Error with "Count is out of range";
+
+      --  Raise Capacity_Error if the new length exceeds the container's
+      --  capacity.
+
+      elsif New_Length > Container.Capacity then
+         raise Capacity_Error with "New length is larger than capacity";
       end if;
 
       J := To_Array_Index (Before);
@@ -1104,7 +1110,7 @@ is
    is
    begin
       if Capacity > Container.Capacity then
-         raise Constraint_Error with "Capacity is out of range";
+         raise Capacity_Error with "Capacity is out of range";
       end if;
    end Reserve_Capacity;