[libcxx-commits] [libcxx] [libc++] Re-introduce special support for narrowing conversions to bool in variant (PR #73121)

via libcxx-commits libcxx-commits at lists.llvm.org
Wed Nov 29 15:04:58 PST 2023


EricWF wrote:

> > Because you made the column. Not accepting float v = 0.0; is pretty sad. So is failing to accept 0 for unsigned.
> 
> Fair enough. I think that's a different level of sad, compare to the ones which silently pick a surprising alternate. But the way the language forgets which things were literals is definitely not great. It usually requires just a single character to fix (0.0f and 0u), but definitely awkward.

Indeed. I was rather keen to address at least the boolean conversion issues. I just wish we had the bool narrowing changes in the language at the time. It's certainly much nicer to accept `std::true_type` -> `bool`.

> 
> Perhaps a better table would have had both 😟 and 😭 entries.

And in that table we'll find the essence of C++.

> 
> Really the root problem here, IMO, is that a giant overload set is a bad way to do sum types. Every other language names the alternates and then has the caller say the name of the one they wanted. Then things like implicit conversions are no more awkward than usual. For that matter, language-level sum type support could also avoid the issue with literals.
> 
> But that's not really an option at this point. (Clearly we need to define `union class`... 😉)

Amen.


https://github.com/llvm/llvm-project/pull/73121


More information about the libcxx-commits mailing list