Avoiding improper std::string initialization with NULL const char* using g++
- by pachanga
A there any g++ options which can detect improper initialization of std::string with NULL const char*?
I was in the process of turning some int fields into std::string ones, i.e:
struct Foo
{
int id;
Foo() : id(0) {}
};
...turned into:
struct Foo
{
std::string id;
Foo() : id(0) {} //oooops!
};
I completely overlooked bad 'id' initialization with 0 and g++ gave me no warnings at all. This error was detected in the run time(std::string constructor threw an exception) but I'd really like to detect such stuff in the compile time. Is there any way?