From: Jonathan Wakely <jwakely.gcc@gmail.com>
To: Jonny Grant <jg@jguk.org>
Cc: gcc-help <gcc-help@gcc.gnu.org>
Subject: Re: std::string add nullptr attribute
Date: Thu, 9 Feb 2023 14:56:12 +0000 [thread overview]
Message-ID: <CAH6eHdQes6i40QxByJ8NvzQnB9+Be+EwJs8t-jv+0+axeUzd3g@mail.gmail.com> (raw)
In-Reply-To: <7e6e3bbf-0dac-0632-0e8f-372bd32a6923@jguk.org>
On Thu, 9 Feb 2023 at 13:28, Jonny Grant wrote:
>
> Hello
> Could GCC's STL implementation add nullptr attribute to prevent code like this compiling?
>
> g++ -Wall -o string string.cpp
>
> std::string c(nullptr);
>
>
> At least GCC STL does reject it at runtime:
>
> terminate called after throwing an instance of 'std::logic_error'
> what(): basic_string: construction from null is not valid
> Aborted (core dumped)
>
>
> Note, my code isn't like this, it is just an example to suggest adding the nullptr attribute, as its clearly already rejected at runtime.
I assume you mean the nonnull attribute. That was added in 2020 and
then reverted because it broke some things:
commit 2635f9e5086318f4560997d9741fdda496b9c801
Author: Ville Voutilainen
Date: Mon Jun 29 23:59:34 2020
Revert "Add a __nonnnull__ attribute to std::string's _CharT* constructor"
This reverts commit b26fd416fb0a734d3f3e56629b6dff2e3c25dd40.
commit b26fd416fb0a734d3f3e56629b6dff2e3c25dd40
Author: Ville Voutilainen
Date: Sun Jun 28 22:47:05 2020
Add a __nonnnull__ attribute to std::string's _CharT* constructor
Add a __nonnnull__ attribute to std::string's _CharT* constructor
* include/bits/basic_string.h (string(_CharT*, const _Alloc&)):
Add a __nonnull__ attribute.
* testsuite/21_strings/basic_string/cons/char/nonnull.cc: New.
* testsuite/21_strings/basic_string/cons/wchar_t/nonnull.cc:
Likewise.
I don't know if anybody analyzed why it broke tests, to see if it
could be made to work.
next prev parent reply other threads:[~2023-02-09 14:56 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-09 13:26 Jonny Grant
2023-02-09 14:56 ` Jonathan Wakely [this message]
2023-02-09 16:30 ` Xi Ruoyao
2023-02-09 17:52 ` Jonathan Wakely
2023-02-10 21:30 ` Jonny Grant
2023-02-10 22:03 ` Jonathan Wakely
2023-02-10 22:38 ` Jonny Grant
2023-02-11 0:32 ` Jonathan Wakely
2023-02-13 22:02 ` Jonny Grant
2023-02-19 20:43 ` Jonny Grant
2023-02-19 21:33 ` Jonny Grant
2023-02-20 10:26 ` Xi Ruoyao
2023-02-20 10:37 ` Jonathan Wakely
2023-02-20 10:54 ` Xi Ruoyao
2023-02-20 11:10 ` Gabriel Ravier
2023-02-20 11:18 ` Marc Glisse
2023-02-20 11:28 ` Segher Boessenkool
2023-02-20 12:00 ` Jonny Grant
2023-02-20 14:50 ` Gabriel Ravier
2023-02-20 11:44 ` Jonny Grant
2023-02-21 15:02 ` Jonny Grant
2023-02-20 11:38 ` Jonny Grant
2023-02-20 11:30 ` Jonny Grant
2023-02-20 12:59 ` Xi Ruoyao
2023-02-20 13:44 ` Jonathan Wakely
2023-02-20 19:21 ` Jonny Grant
2023-02-20 19:35 ` Jonathan Wakely
2023-02-20 19:39 ` Jonny Grant
2023-02-22 20:27 ` Jonny Grant
2023-02-21 15:04 ` Jonny Grant
2023-02-21 22:48 ` Jonny Grant
2023-03-04 15:00 ` Jonny Grant
2023-02-20 11:25 ` Jonny Grant
2023-03-12 22:10 ` Jonny Grant
2023-03-13 10:10 ` Jonathan Wakely
2023-03-13 19:55 ` Jonny Grant
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=CAH6eHdQes6i40QxByJ8NvzQnB9+Be+EwJs8t-jv+0+axeUzd3g@mail.gmail.com \
--to=jwakely.gcc@gmail.com \
--cc=gcc-help@gcc.gnu.org \
--cc=jg@jguk.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).