From: Jonathan Wakely <jwakely@redhat.com>
To: "François Dumont" <frs.dumont@gmail.com>
Cc: "libstdc++@gcc.gnu.org" <libstdc++@gcc.gnu.org>,
gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH][_GLIBCXX_DEBUG] Add basic_string::starts_with/ends_with checks
Date: Fri, 26 Aug 2022 10:31:25 +0100 [thread overview]
Message-ID: <CACb0b4m9AOGjFL9-Hf1tdQ+eKAwd=qAUD7-fwa-62dg_iw5y1w@mail.gmail.com> (raw)
In-Reply-To: <f41daeb7-45dc-4e5c-ce18-17306171a837@gmail.com>
On Sun, 14 Aug 2022 at 16:34, François Dumont via Libstdc++
<libstdc++@gcc.gnu.org> 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 != nullptr
>
> rather than:
> _String != 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.
next prev parent reply other threads:[~2022-08-26 9:31 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-14 15:32 François Dumont
2022-08-15 20:26 ` François Dumont
2022-08-25 16:11 ` François Dumont
2022-08-26 9:33 ` Jonathan Wakely
2022-08-26 9:31 ` Jonathan Wakely [this message]
2022-08-31 4:38 ` [PATCH][_GLIBCXX_DEBUG] Review null string assertions (was: Add basic_string::starts_with/ends_with checks) François Dumont
2022-08-31 9:25 ` Jonathan Wakely
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CACb0b4m9AOGjFL9-Hf1tdQ+eKAwd=qAUD7-fwa-62dg_iw5y1w@mail.gmail.com' \
--to=jwakely@redhat.com \
--cc=frs.dumont@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).