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.133.124]) by sourceware.org (Postfix) with ESMTPS id E76D53858406 for ; Fri, 26 Aug 2022 09:31:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E76D53858406 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=1661506299; 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=ADzGKBIC9cRwa6UWYDr0x9+KKubeUpFPj4IwfS60ipVi3ju9XF2/aLbGYtrA7Qe/La3KeY wviHOyBrDky0HkJ2i+w1S4oIADaJnxWDunO7+nGwayMcuX+AGckewu0imrooTru8wlZgDf iAMJ8dTVGrdJCcW909QjctFEtq5wMJU= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-410-Kblo7bu5PNa8Lw_lw0A99g-1; Fri, 26 Aug 2022 05:31:38 -0400 X-MC-Unique: Kblo7bu5PNa8Lw_lw0A99g-1 Received: by mail-qt1-f198.google.com with SMTP id h19-20020ac85493000000b00343408bd8e5so938125qtq.4 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=FBJbWQCtSW+Z9a1A+f+QMvFogi5LdPkm+qFe7aQHUorCuZo6MCTfCi5c96rhw9nzjC D8vEAjm+su4UMJx28cTT4v6ygHHExGP8dsC6zed4dOrksc37cxAZR00D6AnCk+WJBmYy 6uTrpvjN6zgh2Reqs6ni/ay5DZO8P4luWMtEMVSFnoj6THlz2qlp29W8Hc7Al58NiTwN yTPIww0WqVqOL2AGlkUWRhbC7Smcb1zRunMuun4T7YI0xvlies8IyJqt/QQbG59g16Hn YN0uIlk970TJA1gp1RMiDB0dBCoA6GJVcBcE1dh5Gf4gqtiQ+P20uDDRHnhpB+sQsy9Y qmnQ== X-Gm-Message-State: ACgBeo3tQ7PunDD3f2fD9z+ab9pKUGXPtcW1AzCyL0trUolH0MfZbUlm HFG6QbMSsIiE7n4PzDe6wvJuhf2A+Y1aWcUwIhvh03awmg5UY3hRMf1z3pf3+cYC2ZPLHdfakEE 5PZz+Hr1PhE7yLorQBPn0kA6gBrVatnLYBw== X-Received: by 2002:a0c:a9ca:0:b0:492:61ca:7fcc with SMTP id c10-20020a0ca9ca000000b0049261ca7fccmr7215688qvb.29.1661506298187; 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=-6.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham 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.