--- gcc/ada/libgnat/a-strfix.adb +++ gcc/ada/libgnat/a-strfix.adb @@ -192,7 +192,15 @@ package body Ada.Strings.Fixed is elsif From not in Source'Range or else Through > Source'Last then - raise Index_Error; + -- In most cases this raises an exception, but the case of deleting + -- a null string at the end of the current one is a special-case, and + -- reflects the equivalence with Replace_String (RM A.4.3 (86/3)). + + if From = Source'Last + 1 and then From = Through then + return Source; + else + raise Index_Error; + end if; else declare --- /dev/null new file mode 100644 +++ gcc/testsuite/gnat.dg/fixed_delete.adb @@ -0,0 +1,17 @@ +-- { dg-do run } + +with Ada.Text_IO; use Ada.Text_IO; +with Ada.Strings.Fixed; use Ada.Strings.Fixed; + +procedure Fixed_Delete is + Str : String := "a"; + Str1 : String := Replace_Slice (Str, 2, 2, ""); + Str2 : String := Delete (Str, 2, 2); +begin + if Str1 /= "a" then + raise Program_Error; + end if; + if Str2 /= "a" then + raise Program_Error; + end if; +end Fixed_Delete;