C++ Logo

std-proposals

Advanced search

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

From: Giuseppe D'Angelo <giuseppe.dangelo_at_[hidden]>
Date: Sat, 22 Jul 2023 12:18:45 +0200
On 22/07/2023 10:39, sasho648 via Std-Proposals wrote:
>
> 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.

Technically speaking, a pointer to bool conversion is considered
unconditionally narrowing since C++20

https://eel.is/c++draft/dcl.init.list#7.5

Your usage would still be legal (it's not list-init), but compilers or
linters *could* warn about this. A quick test after: only MSVC warns and
only under /Wall, clang-tidy doesn't even consider this possibility in
its cppcoreguidelines-narrowing-conversions checker.

https://gcc.godbolt.org/z/9a3b5WEbW


My 2 c,

-- 
Giuseppe D'Angelo

Received on 2023-07-22 10:18:48