This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Core dump constructing a C++ string with NULL
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: Tom Browder <tom dot browder at gmail dot com>
- Cc: GCC-help <gcc-help at gcc dot gnu dot org>
- Date: Thu, 13 Jan 2011 20:36:55 +0000
- Subject: Re: Core dump constructing a C++ string with NULL
- References: <AANLkTin_hTLeBJQfTAyS_-hX4Bq4FoghFNX9tAtBpraK@mail.gmail.com>
On 13 January 2011 19:56, Tom Browder wrote:
> 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.
Not if you catch the exception.
> Is that defined behavior according to the standard?
basic_string(const charT* s, const Allocator& a = Allocator());
9 Requires: s shall not be a null pointer.
> If not, what about a g++ enhancement?
We throw an exception, as a gnu extension:
terminate called after throwing an instance of 'std::logic_error'
what(): basic_string::_S_construct NULL not valid
Aborted (core dumped)
> Thanks.
>
> Regards.
>
> -Tom
>
> Thomas M. Browder, Jr.
> Niceville, Florida
> USA
>