From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id A94F6385DC09 for ; Fri, 26 Aug 2022 09:31:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A94F6385DC09 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661506309; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1DOj0mWJEasb6gfwPEUW8HAg6Op+ohkqMeMZY30VDR0=; b=UVtaXKGyFZaUzal6z3KryqVV/Ffr6WnZJdkL+IKSTvSm01CvR0y4LEFFx1kUwFvjxrCw1a CMkHU1+aWIK9yMjoIJArWUU4jY0vZoeLgHT0HCdXQ7Jx2F2nL+9qZPe01/byV0dpt3ruAx CnqCXs+tV/PltY4lDzVSw02hRl3G6PI= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-451-J0B7LTgqOe2wyjqiAineWg-1; Fri, 26 Aug 2022 05:31:38 -0400 X-MC-Unique: J0B7LTgqOe2wyjqiAineWg-1 Received: by mail-qk1-f197.google.com with SMTP id de4-20020a05620a370400b006a9711bd9f8so836367qkb.9 for ; Fri, 26 Aug 2022 02:31:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc; bh=1DOj0mWJEasb6gfwPEUW8HAg6Op+ohkqMeMZY30VDR0=; b=0UnZ7TXXECZNzIIgv5IIFAw9+EX66f+KPIJuhblIWL9KHiWyql9Hk5hl9tf95Fh4Oa A/RqBc7M4R9PSmM4H0n6yffd4rUaMuTr7qh4OXsKaDIwBPAFGoKS2lsvdhZ6t2BZ+3KO hK6P0gQfv088G+L31M9OIgywSunIZR1PxJ89XMn12Knx1PHTxx0WNLfgzBQ1NQCGDNIL adH/hDRZLNstaNhh430IlDf+lrLVUqR8XEi/EFFRQl7j30gWPlj23nNYETSLSVMTBQVu zMxD9EZsrS43GJ+hcG1B10xtKlqNRU9s6kT2fLbdMcUt/xb7tIRzsT4F+lM1uJrCpDmC NDXg== X-Gm-Message-State: ACgBeo1Dva2jvwDwqxArYjK5Eb7DGyuF/bGjsB5twMMUg4o/0oPFrvnK bMVrShy2voQjWOAarpn7cmwHhifLoaCHLoeuza3lmWp3l2Le+oEy3e7iI+Hc8pmrlRqCV8s4BN8 37VQ3r13QGJ3RKqTNINSVxK0KW0++wOY= X-Received: by 2002:a0c:a9ca:0:b0:492:61ca:7fcc with SMTP id c10-20020a0ca9ca000000b0049261ca7fccmr7215682qvb.29.1661506298115; Fri, 26 Aug 2022 02:31:38 -0700 (PDT) X-Google-Smtp-Source: AA6agR4loS9ASc1DLVSSisvwRXIGcrFoK4X4rDW2ClujLMh3dhqSJ1hhVWPfPPjY0RIULBgan5Rln4nIrD2ONg2N+Z8= X-Received: by 2002:a0c:a9ca:0:b0:492:61ca:7fcc with SMTP id c10-20020a0ca9ca000000b0049261ca7fccmr7215623qvb.29.1661506296931; Fri, 26 Aug 2022 02:31:36 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Jonathan Wakely Date: Fri, 26 Aug 2022 10:31:25 +0100 Message-ID: Subject: Re: [PATCH][_GLIBCXX_DEBUG] Add basic_string::starts_with/ends_with checks To: =?UTF-8?Q?Fran=C3=A7ois_Dumont?= Cc: "libstdc++@gcc.gnu.org" , gcc-patches X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Sun, 14 Aug 2022 at 16:34, Fran=C3=A7ois Dumont via Libstdc++ wrote: > > I think we can add those checks. > > Note that I wonder if it was needed as in basic_string_view I see usages > of __attribute__((__nonnull__)). But running the test I saw no impact > even after I try to apply this attribute to the starts_with/ends_with > methods themselves. That should cause warnings, and does when I try it. As you say, the relevant string_view constructor already has that anyway: __attribute__((__nonnull__)) constexpr basic_string_view(const _CharT* __str) noexcept And so does string_view::find. The problem is that those only help if the compiler inlines the calls to those functions and so can propagate the null value all the way down to a function with the attribute. Adding the attribute to the relevant starts_with, ends_with and contains functions makes the diagnostics more likely to be emitted without optimization. > > Also note that several checks like the ones I am adding here are XFAILS > when using 'make check' because of the segfault rather than on a proper > debug checks. Would you prefer to add dg-require-debug-mode to those ? > > libstdc++: [_GLIBCXX_DEBUG] Add basic_string::starts_with/ends_with > checks > > Add simple checks on C string parameters which should not be null. > > Review null string checks to show: > _String !=3D nullptr > > rather than: > _String !=3D 0 I don't really like the extra complexity in the macros, but this does seem like a nice improvement for what users see. We could use __null for C++98, which is a compiler keyword that expands to a null pointer constant, but I'm not sure if that would be clear to all users or not. Maybe 0 is better.