C++ Logo

STD-DISCUSSION

Advanced search

Subject: What makes bool{2} ill-formed?
From: Florian Weimer (fweimer_at_[hidden])
Date: 2020-08-06 10:30:57


I think it is supposed to be a narrowing conversion, but the draft says
this in the definition of a narrowing conversion:

| from an integer type or unscoped enumeration type to an integer type
| that cannot represent all the values of the original type, except
| where the source is a constant expression whose value after integral
| promotions will fit into the target type,

<http://eel.is/c++draft/dcl.init.list#7.4>

With <http://eel.is/c++draft/conv.bool> 2 fits into the bool type. I
don't think there is another meaningful way to get an int into a bool.

It's not a value-preserving conversation, of course, but that's only
part of the narrowing conversion definition for floating point types.

Would it be possible to use more precise language than “represent all
the values“ and “fit into the target type” here?

Thanks,
Florian


STD-DISCUSSION list run by std-discussion-owner@lists.isocpp.org

Older Archives on Google Groups