void foo (const std::string &s) {} int main() { foo(0); //compiles, but invariably causes runtime error return 0; } The compiler (g++ 4.4) apparently interprets 0 as char* NULL, and constructs s by calling string::string(const char*, const Allocator &a = Allocator()). Which is of course useless, because the NULL pointer is not a valid pointer to a c-string. This misinterpretation does not arise when I try to call foo(1), this helpfully produces a compile-time error.
Is there any possibility to get such an error or warning at compile-time when I accidentally call a function like
void bar(const std::string &s, int i=1); with bar(0), forgetting about the string, and actually meaning to have i=0?
basic_string(int)to catch this case. If not, I guess you are out of luck.-W -Wall -Wpointer-arith -Wcast-qualdoes not do the trick, at any rate.