[RFC] std::string(0);

Martin Sebor sebor@roguewave.com
Fri Jun 11 17:21:00 GMT 2004


Daniel Frey wrote:

> Jonathan Wakely wrote:
> 
>> On Fri, Jun 11, 2004 at 02:50:36PM +0200, Daniel Frey wrote:
>>
>>> I would like to suggest a small improvement to basic_string. As the 
>>> subject already says, it's about std::string(0);
>>>
>>> Obviously, it's illegal to pass a const char* to the ctor of 
>>> basic_string that is zero. The current implementation results in a 
>>> SEGV. I would like to catch *some* of the cases at compile-time 
>>> instead of having a crashing program. :)

A conforming implementation is not allowed to reject constructs
such as std::string (0) just because they might cause undefined
behavior at runtime. Consider this well-formed program:

     #include <string>
     int main () {
         if (0) std::string (0);
     }

Martin



More information about the Libstdc++ mailing list