[Ada] AI12-0293-1 Remove pragma Assert

Message ID 20200619082833.GA31340@adacore.com
State New
Headers show
Series
  • [Ada] AI12-0293-1 Remove pragma Assert
Related show

Commit Message

Pierre-Marie de Rodat June 19, 2020, 8:28 a.m.
...and replace it with an explicit check, so it is enabled whether or
not assertions are enabled.

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

2020-06-19  Bob Duff  <duff@adacore.com>

gcc/ada/

	* libgnat/a-ststbo.adb (Write): Replace pragma Assert with "if
	... raise Constraint_Error".

Patch

--- gcc/ada/libgnat/a-ststbo.adb
+++ gcc/ada/libgnat/a-ststbo.adb
@@ -79,16 +79,19 @@  package body Ada.Streams.Storage.Bounded is
    overriding procedure Write
      (Stream : in out Stream_Type; Item : Stream_Element_Array)
    is
-      pragma Assert
-        (Element_Count (Stream) + Item'Length <= Stream.Max_Elements
-           or else (raise Constraint_Error));
-      --  That is a precondition in the RM
-
-      New_Count : constant Stream_Element_Count :=
-        Element_Count (Stream) + Item'Length;
    begin
-      Stream.Elements (Element_Count (Stream) + 1 .. New_Count) := Item;
-      Stream.Count := New_Count;
+      if Element_Count (Stream) + Item'Length > Stream.Max_Elements then
+         --  That is a precondition in the RM
+         raise Constraint_Error;
+      end if;
+
+      declare
+         New_Count : constant Stream_Element_Count :=
+           Element_Count (Stream) + Item'Length;
+      begin
+         Stream.Elements (Element_Count (Stream) + 1 .. New_Count) := Item;
+         Stream.Count := New_Count;
+      end;
    end Write;
 
    -------------------