u/vid512

Warning on optional<int> - bool comparison?

Warning on optional<int> - bool comparison?

I was trying to make sense of what happens when one compares std::optional<int> with bool:

https://godbolt.org/z/597Meh718

Apparently there's some nasty implicit conversion going on under the hood, details of which I don't quite understand.

But from more practical point of view: How to prevent doing this by mistake? MSVC warns by default. Is it possible I enable some similar warning in GCC / Clang? If not why, is there some undesirable false-positive as a result?

u/vid512 — 1 day ago