Is it possible to emit a warning on implicit float to bool conversion in MSVC?

Viewed 95

In this example I want MSVC to emit a warning:

auto func(float f) -> int {
  if(f) { return 654321;} // true if f != 0.0F
  else { return 123456; }
}

So that I'm forced to write:

auto func(float f) -> int {
  if(f != 0) { return 654321;}
  else { return 123456; }
}

Is it possible to make MSVC emit a warning on the implicit conversion in the first example?

1 Answers

No, there is no such warning option in MSVC. You can verify this by compiling your example with /Wall, which enables all warnings, and see that no warning is emitted.

There is, however, one such warning option in Clang: -Wfloat-conversion. The documentation says float to integer, but it includes bool.

Related