<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">FWIW, can you file a bug on this? I think at very least clang should have a warning for this. <div class=""><br class=""></div><div class="">Clang-trunk doesn't seem to flag it but GCC 9.2 does. (<a href="https://godbolt.org/z/3WLQVd" class="">https://godbolt.org/z/3WLQVd</a>)</div><div class=""><div class=""><br class=""></div><div class="">Jared<br class=""><div><br class=""><blockquote type="cite" class=""><div class="">El sep. 13, 2019, a las 13:38, Alexandre Isoard via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a>> escribió:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div style="background-color: rgb(255, 255, 254);" class="">Hello,</div><div style="background-color: rgb(255, 255, 254);" class=""><br class=""></div><div style="background-color: rgb(255, 255, 254);" class="">I encountered a really annoying issue, I am not sure it is Clang or C++ language issue.</div><div style="background-color: rgb(255, 255, 254);" class=""><br class=""></div><div style="background-color: rgb(255, 255, 254);" class="">But basically, the following code:</div><div style="background-color: rgb(255, 255, 254);" class=""><div class=""><div class=""><br class=""><div class=""><span style="color:rgb(0,0,255)" class="">bool</span> foo(<span style="color:rgb(0,0,255)" class="">bool</span> a) {</div><div class="">    <span style="color:rgb(0,0,255)" class="">return</span> ~a;</div><div class="">}</div></div></div></div><div class=""><br class=""></div><div class="">Collapse into:</div><div class=""><br class=""></div><div class=""><div style="background-color: rgb(255, 255, 254);" class=""><div class=""><span style="color:rgb(0,0,255)" class="">bool</span> foo(<span style="color:rgb(0,0,255)" class="">bool</span> a) {</div><div class="">    <span style="color:rgb(0,0,255)" class="">return</span> true;</div><div class="">}</div></div></div><div class=""><br class=""></div><div class="">The explanation is simple:</div><div class="">- a is implicitly converted to int using zext</div><div class="">- int operator~(int) has the unexpected behavior described below</div><div class="">- then icmp ne 0 is used to convert to bool and is always true</div><div class=""><br class=""></div><div class="">Here is the truth table of bool-to-int + operator~(int) + int-to-bool:</div><div class="">false → 0b0000 → 0b0000 → true</div><div class="">true → 0b0001 → 0b1110 → true</div><div class=""><br class=""></div><div class="">Note that we can solve the issue by using sext for bool-to-int conversions.</div><div class="">Should we? Is this a known problem?</div><div class=""><br class=""></div>-- <br class=""><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr" class=""><b class="">Alexandre Isoard</b><br class=""></div></div></div>
_______________________________________________<br class="">cfe-dev mailing list<br class=""><a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a><br class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev<br class=""></div></blockquote></div><br class=""></div></div></body></html>