<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">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:</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><a href="https://github.com/llvm/llvm-project/blob/master/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp#L220">https://github.com/llvm/llvm-project/blob/master/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp#L220</a><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">The documentation (<a href="https://clang.llvm.org/extra/clang-tidy/checks/readability-implicit-bool-conversion.html" style="font-family:Arial,Helvetica,sans-serif">https://clang.llvm.org/extra/clang-tidy/checks/readability-implicit-bool-conversion.html</a>) could arguably use some clarification.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Sep 14, 2019 at 7:05 AM Simon Sandström via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 13/09, Oleg Smolsky wrote:<br>
> On 2019-09-12 09:55, Simon Sandström via cfe-dev wrote:<br>
> > Hello,<br>
> > <br>
> > I'm getting an implicit conversion warning on a piece of code that (from<br>
> > my understanding) I shouldn't. Most likely my understanding is incorrect<br>
> > :-)<br>
> > <br>
> > The piece of code is:<br>
> > <br>
> > bool test1(const int* ptr, int other)<br>
> > {<br>
> >    if (ptr) {<br>
> >      return *ptr == other;<br>
> >    }<br>
> >    return false;<br>
> > }<br>
> > <br>
> > bool test2(const int* ptr, int other)<br>
> > {<br>
> >    return ptr && *ptr == other;<br>
> > }<br>
> > <br>
> > With AllowPointerConditions unset (0) I'm getting warnings both from<br>
> > test1 and test2. With AllowPointerConditions set (1) I'm still getting a<br>
> > warning from test2. Why is that? I guess that I don't understand the<br>
> > 'conditional' part of this option...<br>
> <br>
> I believe both tests are equivalent as far as C++ language semantics go -<br>
> you are using a pointer as a boolean inside a conditional expression. In the<br>
> first case you have an explicit "if" yet in the second you there is a<br>
> logical expression inside the "return". That is, you can rewrite both with<br>
> "ptr != nullptr" to silence the warning.<br>
> <br>
> Oleg.<br>
> <br>
<br>
Well yes, I can silence it by explicitly comparing it to nullptr, but<br>
shouldn't it by silenced by using the AllowPointerConditions option as<br>
well? In both cases above, that is.<br>
<br>
- Simon<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div>