[cfe-dev] clang-tidy: problem with readability-implicit-bool-conversion AllowPointerConditions

Simon Sandström via cfe-dev cfe-dev at lists.llvm.org
Fri Sep 20 03:52:42 PDT 2019


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



More information about the cfe-dev mailing list