<div dir="ltr">In C++ at least, there seems to be a difference:<br><br><div>|-VarDecl 0x7da9f60 <cast.cc:1:1, col:14> col:5 x 'int' cinit</div><div>| `-CStyleCastExpr 0x7daa040 <col:9, col:14> 'int' <NoOp></div><div>|   `-ImplicitCastExpr 0x7daa028 <col:14> 'int' <IntegralCast></div><div>|     `-CXXBoolLiteralExpr 0x7daa000 <col:14> '_Bool' true</div><div>`-VarDecl 0x7daa078 <line:2:1, col:9> col:5 y 'int' cinit</div><div>  `-ImplicitCastExpr 0x7daa0f0 <col:9> 'int' <IntegralCast></div><div>    `-CXXBoolLiteralExpr 0x7daa0d8 <col:9> '_Bool' true<br><br>One has a CStyleCastExpr, one doesn't.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, May 9, 2016 at 1:15 PM, Michael Layzell via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div>I was trying to write a clang static analysis for detecting implicit bool to int casts. Namely, I wanted to allow forms like:<br><br></div>int x = (int) true;<br><br></div>But disallow forms like:<br><br></div>int x = true;<br><br></div>Unfortunately, it seems like both of these generate implicit cast AST nodes, namely I get the following AST tree for the explicitly casted form:<br><br><pre>    `-DeclStmt 0x7fae2407a118 <line:51:3, col:30>
      `-VarDecl 0x7fae2407a050 <col:3, col:26> col:7 x 'int' cinit
        `-CStyleCastExpr 0x7fae2407a0f0 <col:21, col:26> 'int' <NoOp>
          `-ImplicitCastExpr 0x7fae2407a0d8 <col:26> 'int' <IntegralCast>
            `-CXXBoolLiteralExpr 0x7fae2407a0b0 <col:26> '_Bool' true</pre>How should I distinguish between the two forms reliably, such that explicit casts are never matched, but implicit casts are matched, when an explicit cast still inserts an implicit cast, and then just becomes a NoOp?<br></div>
<br>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div>