I have always been using GCC but from what I have seen on this forum and elsewhere it seems like VC++ is complaining much more about implicit conversions that could lead to loss of data (e.g. double -> int).
I have been considering using the GCC's compiler flag -Wconversion but I'm not sure if I should. It seems like I would have to put explicit casts all over the place. It might be OK if I only used default types, int, double, bool, but if other types are used it seems really inconvenient.
1 2
std::uint16_t a = 2;
std::uint16_t b = static_cast<std::uint16_t>(a + 2);
The C++11 narrowing rules (which I'm not a fan of) already force you to add a lot of explicit casts so doing it everywhere would be more consistent I guess, but so far I have been trying to avoid using curly brackets when initializing for that reason.
Is there anyone that actually use -Wconversion? Is it worth it?
Well, I use -Wconversion (and -Wsign-conversion.) But then I normally work with Visual Studo compiling /W4 so am used to this kind of warning. In fact, the reason I use -Wconversion is to get the GCC compiler to complain about the same things as the Microsoft compiler.
I think so!
But then I'm prob a bit neurotic...
Andy
PS Checking one of my makefiles, I see that even after specifying -Wall -Wextra and -pedantic I've gone on to add not only -Wconversion and -Wsign-conversion but also -Wunused -Wunreachable-code -Wno-write-strings