Re: std::string(false) - is not a compliation error
Krzysztof Ziolkowski <myName_mySurname@mentor.com> wrote:
"Igor Tandetnik" <itandetnik@mvps.org> wrote in message
news:eQa4bYdyKHA.4240@TK2MSFTNGP06.phx.gbl...
Right now, string's constructor crashes when passed a NULL pointer,
giving you a chance to drop into
the debugger then and there. If it were to explicitly check for
NULL, what should it do differently and
what additional benefit would you hope to gain from the new behavior?
In my tests (VS2008) constructor do not crash, the first use of
string does.
Are you sure? I don't see how this is possible. The constructor needs to =
copy actual characters from the pointed-to location, so it must =
dereference the pointer, which would lead to a crash.
Are you debugging a release build, by any chance? In this case, it's =
likely the machine code being executed doesn't line up well with source =
lines, which may create an illusion that the crash occurs after the line =
invoking the constructor has been passed. It's also possible the =
constructor got inlined, further complicating diagnostic.
Of course, adding an extra check to debug build only, as you suggested, =
wouldn't help you debug a release build.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not =
necessarily a good idea. It is hard to be sure where they are going to =
land, and it could be dangerous sitting under them as they fly overhead. =
-- RFC 1925