C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Require diagnostic for array to bool conversion

From: sasho648 <sasho648_at_[hidden]>
Date: Sun, 23 Jul 2023 14:56:49 +0300
But who am I to judge - do you - never expected a sane answer from this
group anyway.

On Sun, Jul 23, 2023 at 2:54 PM sasho648 <sasho648_at_[hidden]> wrote:

> Definitely some useful case for array to bool though - except the only one
> was named in the first sincere email before you mentioned C compatibility
> which is a misnomer for C++.
>
> On Sun, Jul 23, 2023 at 2:53 PM sasho648 <sasho648_at_[hidden]> wrote:
>
>> Well I found it useful to not need to type explicit cast on pointer
>> conversions which is a part of C but not of C++.
>>
>> Maybe someone finds array parameters useful in some corner case as well.
>>
>> But nobody will find comma expression used inside [ and ] useful for sure.
>>
>> On Sun, Jul 23, 2023 at 2:13 PM Alejandro Colomar via Std-Proposals <
>> std-proposals_at_[hidden]> wrote:
>>
>>> Linters can usually warn about such conversions. Try clang-tidy(1).
>>>
>>> And once you have guarantee that your code is fine, thanks to running
>>> linters on your own code, why would you want to forbid it in the standard?
>>> Maybe someone finds it useful in some corner case (likely to be in
>>> C-compatible code).
>>>
>>> On Sat, Jul 22, 2023, 10:40 sasho648 via Std-Proposals <
>>> std-proposals_at_[hidden]> wrote:
>>>
>>>>
>>>> int arr[2];
>>>> bool test = arr;
>>>> bool teststr = "string";
>>>>
>>>>
>>>> Which I came across while having a function like this:
>>>>
>>>> void set_property(const char *name, const char *default_value);
>>>> void set_property_bool(const char*name, bool default_value);
>>>>
>>>> Where I thought the bool one was expecting a string as second argument
>>>> as well and so I wrote:
>>>>
>>>> set_property_bool("test", "true");
>>>>
>>>> Which compiled fine and even worked until I decided to change it to:
>>>>
>>>> set_property_bool("test", "false");
>>>>
>>>> In my opinion such a conversion holds no value - since it has only one
>>>> outcome - and furthermore I think it's against C++ type safety - and even
>>>> furthermore I think currently it's only purpose is obfuscation contests or
>>>> creating hard to diagnose bugs as the case I've shown above.
>>>> --
>>>> Std-Proposals mailing list
>>>> Std-Proposals_at_[hidden]
>>>> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>>>>
>>> --
>>> Std-Proposals mailing list
>>> Std-Proposals_at_[hidden]
>>> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>>>
>>

Received on 2023-07-23 11:57:01