Re: strings and NULL argument passing
On Nov 14, 1:25 am, Rolf Magnus <ramag...@t-online.de> wrote:
James Kanze wrote:
It's undefined behavior. With a good implementation of
std::string, it won't compile.
Would it actually be allowed by the standard to have an
additional constructor in std::string?
That's a good question. If it doesn't affect the overload
resolution of legal calls to the constructor, I think so, if
only under the as if rule. Thus, if as a library implementor, I
do something like:
namespace std {
template< ... >
class basic_string
{
// ...
private:
struct _Hidden {} ;
basic_string( int _Hidden::*,
Allocator const& = Allocator() ) ;
} ;
can a legal program detect the presence of the additional
constructor?
(One issue might be whether the following program is legal:
#include <string>
void
f( bool t )
{
if ( t ) {
std::string s(0) ;
}
}
int
main()
{
f( false ) ;
}
..)
In practice, on thinking about it, I'm not sure that it's worth
the effort. I only catches the case where you initialize with a
null pointer constant (0, NULL or the like), which is, one would
hope, pretty rare. You still need a run-time check (generally
provided directly by the hardware) in case of a variable which
happens to contain a null ponter.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34