[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#192225: string::string(const char *) called with non-null-terminated string



On Wed, May 07, 2003 at 07:54:10PM -0600, Jason Gunthorpe wrote:

> What gives? GCC used to produce warnings when it created temporary objects
> in this manner.

(Disclaimer: I'm no C++ expert)

Well, in C++, such implicit temporaries are quite normal, although
sometimes quite confusing.  For example, the following code would be
perfectly valid and normal:

void foo(const std::string &str) {
    std::cout << str << std::endl;
}

void bar(void) {
    foo("Hello, world!"); // Implicit conversion to std::string
}

For constructors that shouldn't be used implicitly there's the
`explicit' keyword.  Obviously, it's not used with the
string::string(const char *) constructor.

As for GCC having produced warnings, it can't have been quite recently
since the code in question has been in CVS since October 1998 :-)

	Sami



Reply to: