From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 127866 invoked by alias); 8 Jul 2019 08:19:03 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 127798 invoked by uid 89); 8 Jul 2019 08:19:03 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.0 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.1 spammy=libgnat, index_error, Replace_String, sk:fixed_d X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 08 Jul 2019 08:19:02 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id EA96156181; Mon, 8 Jul 2019 04:18:59 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id ugI1PFThna0u; Mon, 8 Jul 2019 04:18:59 -0400 (EDT) Received: from tron.gnat.com (tron.gnat.com [205.232.38.10]) by rock.gnat.com (Postfix) with ESMTP id 1249856184; Mon, 8 Jul 2019 04:18:58 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4862) id 112D1602; Mon, 8 Jul 2019 04:18:58 -0400 (EDT) Date: Mon, 08 Jul 2019 08:19:00 -0000 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Ed Schonberg Subject: [Ada] Semantics of Delete for fixed strings Message-ID: <20190708081857.GA80632@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="8t9RHnE3ZwKMSgU+" Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes X-SW-Source: 2019-07/txt/msg00549.txt.bz2 --8t9RHnE3ZwKMSgU+ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 741 This patch corrects a bug in the implementation of Delete in an unusual boundary case: the RM describes the semantics of Delete as equivalent to that of Replace_String with a null argument. As a result, deleting a null string that starts past the end of its argument is a noop and must not raise Index_Error. Tested on x86_64-pc-linux-gnu, committed on trunk 2019-07-08 Ed Schonberg gcc/ada/ * libgnat/a-strfix.adb (Delete): The RM describes the semantics of Delete as equivalent to that of Replace_String with a null argument. As a result, deleting a null string that starts past the end of its argument is a noop and must not raise Index_Error. gcc/testsuite/ * gnat.dg/fixed_delete.adb: New testcase. --8t9RHnE3ZwKMSgU+ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="patch.diff" Content-length: 1173 --- 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; --8t9RHnE3ZwKMSgU+--