So today I wrote a fairly hard to find bug where I initialized a std::string to nullptr (not a pointer to std::string, but the value itself). I\'ve found apparently it\'s on
That's simply because there are constructors (number (5) in the link) and assignment operators (number (3) in the link) for std::string that accept a const char*
, and hence the nullptr
matches.
Before C++11 (and therefore before nullptr
), the same problem occurred when you tried to construct from 0
or NULL
. All those cases were illegal and result in undefined behaviour, although at least one STL (RogueWave?) accepted it in the past and generated an empty string.