gcc warning flags for implicit conversions

Viewed 3399

I recently had a bug in a similar context to next one:

double getSomeValue()
{
    return 4.0;
}
...
std::string str;
str = getSomeValue();

As you can see here is easy to spot the problem, but in a large code base where getSomeValue() is not in the same file with the calling code it might be difficult to spot this double to std::string silent conversion. GCC compiles this code fine with -Wall -Wextra -Werror (sample output here, I don't know what warning flags were used: http://ideone.com/BTXBFk).

How may I force GCC to emit warnings for these dangerous implicit conversions? I tried -Wconversion, but it is very strict and it causes errors in most included headers for common cases like unsigned - 1. Is there a weaker version of -Wconversion?

2 Answers
Related