Date: Wed, 3 Sep 2025 09:00:01 +0200
On 02/09/2025 23:59, Sebastian Wittmeier via Std-Proposals wrote:
> Yes, it could have worked with explicit casts to int, if done so from
> the beginning.
>
> But those are really basic math operations, which have worked for
> decades without change on various platforms from small embedded systems
> to PCs to GPUs to specify algorithms.
>
> There is lots of complex code out there using those implicit conversions
> from bool to 0 and 1.
>
> I do not think it is feasible to disallow those now (at least in
> general, a safety profile could be more acceptable).
>
> Other code:
>
> bool b0, b1, b2; // bits
>
> int number = b2 * 4 + b1 * 2 + b0;
>
>
Of course it is always difficult to remove existing behaviour that is
used in real-world code. Any restrictions on the implicit conversions
of bool would have to be done in stages, with deprecation first.
I would think that it is reasonable to continue to allow multiplication
of bool with a scalar - that is more common in real code (IME) and
unlikely to be an error. Perhaps addition of a bool and a scalar should
also be allowed. But arithmetic on two bools is, I think, rarer and
less necessary, and also more likely to be in error.
But I doubt if it is practical to do anything about it now in the
standard. It is something that can be left for compiler warnings.
> Yes, it could have worked with explicit casts to int, if done so from
> the beginning.
>
> But those are really basic math operations, which have worked for
> decades without change on various platforms from small embedded systems
> to PCs to GPUs to specify algorithms.
>
> There is lots of complex code out there using those implicit conversions
> from bool to 0 and 1.
>
> I do not think it is feasible to disallow those now (at least in
> general, a safety profile could be more acceptable).
>
> Other code:
>
> bool b0, b1, b2; // bits
>
> int number = b2 * 4 + b1 * 2 + b0;
>
>
Of course it is always difficult to remove existing behaviour that is
used in real-world code. Any restrictions on the implicit conversions
of bool would have to be done in stages, with deprecation first.
I would think that it is reasonable to continue to allow multiplication
of bool with a scalar - that is more common in real code (IME) and
unlikely to be an error. Perhaps addition of a bool and a scalar should
also be allowed. But arithmetic on two bools is, I think, rarer and
less necessary, and also more likely to be in error.
But I doubt if it is practical to do anything about it now in the
standard. It is something that can be left for compiler warnings.
Received on 2025-09-03 07:00:12