<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 24, 2015 at 5:05 PM, Richard <span dir="ltr"><<a href="mailto:legalize@xmission.com" target="_blank">legalize@xmission.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
In article <CAENS6EvT8Z0Y5Vn8bHh6XKHiBa8G1JSFLo3EL===<a href="mailto:wXExDVFKWA@mail.gmail.com">wXExDVFKWA@mail.gmail.com</a>>,<br>
<span class="">    David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> writes:<br>
<br>
> On Sun, Mar 22, 2015 at 10:38 AM, Richard <<a href="mailto:legalize@xmission.com">legalize@xmission.com</a>> wrote:<br>
><br>
</span>> > [...]<br>
<span class="">> > How can I identify these implicit boolean statements?  When I enqure<br>
> > the type of the conditional expression in these cases by using<br>
> > Expr::getType(), they both tell me that they are bool.<br>
><br>
> If you ast-dump (or is it dump-ast? I forget) the clang invocation, you<br>
> should see the AST that builds these and I believe you'll see that the RHS<br>
> is an ImplicitConversionExpr or something like that, which is what's hiding<br>
> the underlying type. There are utility functions for stripping implicit<br>
> casts and parentheses (utilities are probably in ASTContext).<br>
<br>
</span>Thanks David, I've prototyped this and it works pretty well.  I want<br>
to make sure I cover all the different ways that an implicit bool<br>
conversion can take place.  The ones I can think of were the<br>
arithmetic expressions that are implicitly converted to bool by<br>
comparing them to zero (integral types, pointers, floating-point<br>
types) and objects (class, struct, union) that provide an operator<br>
bool() that does the conversion.  For the former I am replacing<br>
'if (e) return true; else return false;' with 'return e != 0;<br></blockquote><div><br>Maybe special case chars for "return e != '\0';" ? hard to tell if it's chars being used as bytes or chars being used as textual characters, though... - and hard to tell what the common codebase convention is as to whether "return e;" is better than "return e != 0;" etc... - I'd be sort of inclined to just use the expression directly if it's valid (eg: for builtin types and implicit conversion operators).<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
and for the latter I am replacing with 'return bool(e);'.<br></blockquote><div><br>If the type's conversion operator is implicit, it might be fine to "return e;"<br>If the type's conversion operator is explicit, it might be more suitable to use static_cast<bool>. There is "return !!e;" but that's lame... otherwise there's probably more explicit type-specific ways to test the object, but you won't be able to suggest those automatically. (eg: "return o != nullptr;" for a unique_ptr, etc)<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Am I missing anything?<br>
<div class="HOEnZb"><div class="h5">--<br>
"The Direct3D Graphics Pipeline" free book <<a href="http://tinyurl.com/d3d-pipeline" target="_blank">http://tinyurl.com/d3d-pipeline</a>><br>
     The Computer Graphics Museum <<a href="http://ComputerGraphicsMuseum.org" target="_blank">http://ComputerGraphicsMuseum.org</a>><br>
         The Terminals Wiki <<a href="http://terminals.classiccmp.org" target="_blank">http://terminals.classiccmp.org</a>><br>
  Legalize Adulthood! (my blog) <<a href="http://LegalizeAdulthood.wordpress.com" target="_blank">http://LegalizeAdulthood.wordpress.com</a>><br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
</div></div></blockquote></div><br></div></div>