public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Ian Lance Taylor <iant@google.com>
To: Tom Browder <tom.browder@gmail.com>
Cc: GCC-help <gcc-help@gcc.gnu.org>
Subject: Re: Core dump constructing a C++ string with NULL
Date: Thu, 13 Jan 2011 20:59:00 -0000	[thread overview]
Message-ID: <mcrbp3ko6zr.fsf@google.com> (raw)
In-Reply-To: <AANLkTin_hTLeBJQfTAyS_-hX4Bq4FoghFNX9tAtBpraK@mail.gmail.com>	(Tom Browder's message of "Thu, 13 Jan 2011 13:56:26 -0600")

Tom Browder <tom.browder@gmail.com> writes:

> It would be nice if this would construct an empty string:
>
>   #include <string>
>   std::string s(0);
>
> At the moment that gives a core dump.
>
> Is that defined behavior according to the standard?  If not, what
> about a g++ enhancement?

The standard says that you may only pass a valid pointer to the
std::string constructor.  You are passing an invalid pointer, so your
code is undefined.

As to whether libstdc++ should check for NULL, that is a perennial
question: should we slow down the library a tiny bit for everybody in
order to do better handling of an undefined case for those who find it
more convenient?  There is no clearly correct answer.

Ian

  parent reply	other threads:[~2011-01-13 20:59 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-13 19:56 Tom Browder
2011-01-13 20:04 ` Brian Budge
2011-01-13 20:50 ` Jonathan Wakely
2011-01-13 20:59 ` Ian Lance Taylor [this message]
2011-01-14 16:20   ` Tom Browder
2011-01-14 16:47     ` Jonathan Wakely
2011-01-14 17:00       ` Tom Browder
2011-01-14 17:05         ` Jonathan Wakely
2011-01-14 17:17           ` Jonathan Wakely
2011-01-14 17:39             ` Tom Browder
2011-01-14 17:38         ` Ian Lance Taylor
2011-01-14 17:44           ` Tom Browder
2011-01-14 17:48             ` Brian Budge
2011-01-15 12:33               ` Tom Browder
2011-01-15 13:52                 ` Jonathan Wakely
2011-01-15 14:06                   ` Tom Browder
2011-01-15 14:12                     ` Jonathan Wakely
2011-01-15 14:15                       ` Jonathan Wakely
2011-01-15 15:06                         ` Tom Browder
2011-01-14 18:04             ` 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=mcrbp3ko6zr.fsf@google.com \
    --to=iant@google.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=tom.browder@gmail.com \
    /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).