When compiled with -Wall, the following code reports a warning only on the live path, as showcased in https://godbolt.org/z/3PD-eF int case0(int num) { if(0) return num / 0; << no warning else return 1; } int case1(int num) { if(num) return num / 0; << warning else return 1; } Yet, when the following code is compiled with -Wall -Wdouble-conversion, we have a warning even in the dead path, as showcased in https://godbolt.org/z/58Q5oA double foo(double); int case0(float num) { if(0) return foo(num); << warning else return 1; } int case1(float num) { if(num) return foo(num); << warning else return 1; }
Thanks for reporting this! I don't see how a consistency argument applies here: one warning is about a potentially undesired implicit conversion, whereas the other is about trivially obvious undefined behavior. If our other implicit conversion warnings take path liveness into account, then I think there's a great case to make this consistent with those. Picking an arbitrary (but similar in spirit) implicit conversion warning, this doesn't appear to be the case: https://godbolt.org/z/bp8tlg
You argumentation makes sense to me. I still have difficulties to understand in which situation a warning on trivially dead code may be useful, but that's another story.