[cfe-dev] clang-tidy: problem with readability-implicit-bool-conversion AllowPointerConditions
Yitzhak Mandelbaum via cfe-dev
cfe-dev at lists.llvm.org
Fri Sep 20 05:31:06 PDT 2019
If I'm understanding your argument correctly, you're saying that if we
allow pointer-to-bool in a conditional context because it is "tagged" by
the context, then we can similarly argue that "return" tags the context?
If so, I see your point, but "return" doesn't imply a bool type whereas the
others do. So, it's different than an arbitrary expression context, but,
IMO, not enough.
Still, this is all a matter of taste, so if you are willing to write the
patch to add that configuration option, I'd think you'll get a fair
consideration from reviewers.
On Fri, Sep 20, 2019 at 6:52 AM Simon Sandström <simon at nikanor.nu> wrote:
> On 18/09, Yitzhak Mandelbaum wrote:
> > In the second case, you're not using it in a condition context -- it's
> just
> > a normal boolean-valued expression. The flag only disables the check
> when
> > these implicit casts appear in the context of "conditions": if, while,
> for,
> > etc. Here's the relevant code:
> >
> >
> https://github.com/llvm/llvm-project/blob/master/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp#L220
> >
> > The documentation (
> >
> https://clang.llvm.org/extra/clang-tidy/checks/readability-implicit-bool-conversion.html
> )
> > could arguably use some clarification.
> >
> > On Sat, Sep 14, 2019 at 7:05 AM Simon Sandström via cfe-dev <
> > cfe-dev at lists.llvm.org> wrote:
> >
>
> Thank you, that explains it. Besides updating the documentation, do you
> think it would be useful to add a new option to allow implicit casts
> like in the second case? AllowPointerReturnStatement or whatever.
>
> Maybe there are other issues that can arise from implicitly casting
> pointer to bool in return statement that cannot happen in a condition
> context? Or it's just preferred to explicitly check against nullptr in a
> return statement?
>
> - Simon
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20190920/66f138bc/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4847 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20190920/66f138bc/attachment.bin>
More information about the cfe-dev
mailing list