This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [v3] char_traits error checking
On Tue, Mar 12, 2002 at 10:49:36AM -0500, Phil Edwards wrote:
> On Mon, Mar 11, 2002 at 09:35:02PM -0800, Benjamin Kosnik wrote:
> >
> > 21.3.1 - basic_string constructors
> > basic_string(const charT* s, const Allocator& a = Allocator());
> > -9- Requires: s shall not be a null pointer.
>
> I looked at this as part of PR 5258. The way the ctors are arranged in
> basic_string.tcc doesn't seem to give us any opportunities to do checking on
> the arguments: the string data is built (and dereferenced) in the member
> init list, so no "if NULL throw logic_error" is possible unless we break
> that out into a ctor body.
Not a problem -- change ": member(p)" to ": member(__throw_if_null(p))".
> As for the member functions, if we make "no NULL pointers" a string class
> invariant / postcondition, those problems are neatly sidestepped.
For string, it's worth giving a decent diagnostic for null pointers
even though we don't have to. Beginners rely very heavily on string.
Nathan Myers
ncm at cantrip dot org