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?
std::string::string(int);
. That would be a better match, and thus cause a compile-time error. – MSalters Mar 9 '10 at 11:47int
tostring
. Modifystd::basic_string
in g++'s standard headers, check that the new code compiles, then change it back fast, before anyone notices. – Steve Jessop Mar 9 '10 at 12:01