<div dir="ltr"><div style="font-size:12.8px">Hi all!</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">I'm interested in developing a clang static checker for enum comparison in switch and throwing a warning.</div><div style="font-size:12.8px">I found out that it already exists in if <span style="font-size:12.8px">comparison</span><span style="font-size:12.8px"> </span><span style="font-size:12.8px"> in clang but my question is:</span></div><div style="font-size:12.8px">Is this on purpose that different enum types don't send warning or int and enum comparison in switches but send in if?</div><div style="font-size:12.8px">Example:</div><div style="font-size:12.8px"><pre class="gmail-code gmail-highlight gmail-js-syntax-highlight gmail-cpp gmail-white" style="box-sizing:border-box;overflow:auto;font-family:menlo,"liberation mono",consolas,"dejavu sans mono","ubuntu mono","courier new","andale mono","lucida console",monospace;font-size:13px;padding:10px;margin-top:12px;margin-bottom:12px;line-height:1.6em;word-break:break-all;word-wrap:break-word;border:1px solid rgb(229,229,229);border-radius:2px"><code style="box-sizing:border-box;font-family:menlo,"liberation mono",consolas,"dejavu sans mono","ubuntu mono","courier new","andale mono","lucida console",monospace;font-size:inherit;padding:0px;background-color:transparent;border-radius:0px;white-space:pre-wrap;word-wrap:normal;margin-top:0px;word-break:keep-all"><span class="gmail-k" style="color:inherit;box-sizing:border-box;margin-top:0px;font-weight:bold">enum</span><font color="rgba(0, 0, 0, 0)"> </font><span class="gmail-n" style="color:inherit;box-sizing:border-box">MIXED_ENUMS_e</span><font color="rgba(0, 0, 0, 0)"> </font><span class="gmail-p" style="color:inherit;box-sizing:border-box">{</span><font color="rgba(0, 0, 0, 0)"> </font><span class="gmail-n" style="color:inherit;box-sizing:border-box">E1</span><span class="gmail-p" style="color:inherit;box-sizing:border-box">,</span><font color="rgba(0, 0, 0, 0)"> </font><span class="gmail-n" style="color:inherit;box-sizing:border-box">E2</span><font color="rgba(0, 0, 0, 0)"> </font><span class="gmail-p" style="color:inherit;box-sizing:border-box">};</span><font color="rgba(0, 0, 0, 0)">
</font><span class="gmail-k" style="color:inherit;box-sizing:border-box;font-weight:bold">enum</span><font color="rgba(0, 0, 0, 0)"> </font><span class="gmail-n" style="color:inherit;box-sizing:border-box">MIXED_ENUMS_f</span><font color="rgba(0, 0, 0, 0)"> </font><span class="gmail-p" style="color:inherit;box-sizing:border-box">{</span><font color="rgba(0, 0, 0, 0)"> </font><span class="gmail-n" style="color:inherit;box-sizing:border-box">F0</span><span class="gmail-p" style="color:inherit;box-sizing:border-box">,</span><font color="rgba(0, 0, 0, 0)"> </font><span class="gmail-n" style="color:inherit;box-sizing:border-box">F1</span><span class="gmail-p" style="color:inherit;box-sizing:border-box">,</span><font color="rgba(0, 0, 0, 0)"> </font><span class="gmail-n" style="color:inherit;box-sizing:border-box">F2</span><span class="gmail-p" style="color:inherit;box-sizing:border-box">,</span><font color="rgba(0, 0, 0, 0)"> </font><span class="gmail-n" style="color:inherit;box-sizing:border-box">F3</span><font color="rgba(0, 0, 0, 0)"> </font><span class="gmail-p" style="color:inherit;box-sizing:border-box">};</span><font color="rgba(0, 0, 0, 0)">
</font><span class="gmail-kt" style="color:rgb(68,85,136);box-sizing:border-box;font-weight:bold">void</span><font color="rgba(0, 0, 0, 0)"> </font><span class="gmail-nf" style="color:rgb(153,0,0);box-sizing:border-box;font-weight:bold">mixed_enums</span><span class="gmail-p" style="color:inherit;box-sizing:border-box">(</span><span class="gmail-n" style="color:inherit;box-sizing:border-box">MIXED_ENUMS_e</span><font color="rgba(0, 0, 0, 0)"> </font><span class="gmail-n" style="color:inherit;box-sizing:border-box">ee</span><span class="gmail-p" style="color:inherit;box-sizing:border-box">)</span><font color="rgba(0, 0, 0, 0)">
</font><span class="gmail-p" style="color:inherit;box-sizing:border-box">{</span><font color="rgba(0, 0, 0, 0)">
</font><span class="gmail-kt" style="color:rgb(68,85,136);box-sizing:border-box;font-weight:bold">int</span><font color="rgba(0, 0, 0, 0)"> </font><span class="gmail-n" style="color:inherit;box-sizing:border-box">x</span><span class="gmail-p" style="color:inherit;box-sizing:border-box">;</span><font color="rgba(0, 0, 0, 0)">
</font><span class="gmail-k" style="color:inherit;box-sizing:border-box;font-weight:bold">switch</span><font color="rgba(0, 0, 0, 0)"> </font><span class="gmail-p" style="color:inherit;box-sizing:border-box">(</span><span class="gmail-n" style="color:inherit;box-sizing:border-box">ee</span><span class="gmail-p" style="color:inherit;box-sizing:border-box">)</span><font color="rgba(0, 0, 0, 0)">
</font><span class="gmail-p" style="color:inherit;box-sizing:border-box">{</span><font color="rgba(0, 0, 0, 0)">
</font><span class="gmail-k" style="color:inherit;box-sizing:border-box;font-weight:bold">case</span><font color="rgba(0, 0, 0, 0)"> </font><span class="gmail-n" style="color:inherit;box-sizing:border-box">E1</span><span class="gmail-p" style="color:inherit;box-sizing:border-box">:</span><font color="rgba(0, 0, 0, 0)"> </font><span class="gmail-n" style="color:inherit;box-sizing:border-box">x</span><font color="rgba(0, 0, 0, 0)"> </font><span class="gmail-o" style="color:inherit;box-sizing:border-box;font-weight:bold">=</span><font color="rgba(0, 0, 0, 0)"> </font><span class="gmail-mi" style="color:rgb(0,153,153);box-sizing:border-box">1</span><span class="gmail-p" style="color:inherit;box-sizing:border-box">;</span><font color="rgba(0, 0, 0, 0)"> </font><span class="gmail-k" style="color:inherit;box-sizing:border-box;font-weight:bold">break</span><span class="gmail-p" style="color:inherit;box-sizing:border-box">;</span><font color="rgba(0, 0, 0, 0)">
</font><span class="gmail-k" style="color:inherit;box-sizing:border-box;font-weight:bold">case</span><font color="rgba(0, 0, 0, 0)"> </font><span class="gmail-n" style="color:inherit;box-sizing:border-box">F1</span><span class="gmail-p" style="color:inherit;box-sizing:border-box">:</span><font color="rgba(0, 0, 0, 0)"> </font><span class="gmail-n" style="color:inherit;box-sizing:border-box">x</span><font color="rgba(0, 0, 0, 0)"> </font><span class="gmail-o" style="color:inherit;box-sizing:border-box;font-weight:bold">=</span><font color="rgba(0, 0, 0, 0)"> </font><span class="gmail-mi" style="color:rgb(0,153,153);box-sizing:border-box">2</span><span class="gmail-p" style="color:inherit;box-sizing:border-box">;</span><font color="rgba(0, 0, 0, 0)"> </font><span class="gmail-k" style="color:inherit;box-sizing:border-box;font-weight:bold">break</span><span class="gmail-p" style="color:inherit;box-sizing:border-box">;</span><font color="rgba(0, 0, 0, 0)"> </font><span class="gmail-c1" style="color:rgb(153,153,136);box-sizing:border-box;font-style:italic">// TODO warning: ee and F1 have different types.
</span><font color="rgba(0, 0, 0, 0)"> </font><span class="gmail-p" style="color:inherit;box-sizing:border-box">}</span><font color="rgba(0, 0, 0, 0)">
</font><span class="gmail-k" style="color:inherit;box-sizing:border-box;font-weight:bold">switch</span><font color="rgba(0, 0, 0, 0)"> </font><span class="gmail-p" style="color:inherit;box-sizing:border-box">(</span><span class="gmail-n" style="color:inherit;box-sizing:border-box">x</span><span class="gmail-p" style="color:inherit;box-sizing:border-box">)</span><font color="rgba(0, 0, 0, 0)">
</font><span class="gmail-p" style="color:inherit;box-sizing:border-box">{</span><font color="rgba(0, 0, 0, 0)">
</font><span class="gmail-k" style="color:inherit;box-sizing:border-box;font-weight:bold">case</span><font color="rgba(0, 0, 0, 0)"> </font><span class="gmail-n" style="color:inherit;box-sizing:border-box">E1</span><span class="gmail-p" style="color:inherit;box-sizing:border-box">:</span><font color="rgba(0, 0, 0, 0)"> </font><span class="gmail-o" style="color:inherit;box-sizing:border-box;font-weight:bold">++</span><span class="gmail-n" style="color:inherit;box-sizing:border-box">x</span><span class="gmail-p" style="color:inherit;box-sizing:border-box">;</span><font color="rgba(0, 0, 0, 0)"> </font><span class="gmail-k" style="color:inherit;box-sizing:border-box;font-weight:bold">break</span><span class="gmail-p" style="color:inherit;box-sizing:border-box">;</span><font color="rgba(0, 0, 0, 0)"> </font><span class="gmail-c1" style="color:rgb(153,153,136);box-sizing:border-box;font-style:italic">// TODO warning: x and E1 have different types.
</span><font color="rgba(0, 0, 0, 0)"> </font><span class="gmail-k" style="color:inherit;box-sizing:border-box;font-weight:bold">case</span><font color="rgba(0, 0, 0, 0)"> </font><span class="gmail-n" style="color:inherit;box-sizing:border-box">F3</span><span class="gmail-p" style="color:inherit;box-sizing:border-box">:</span><font color="rgba(0, 0, 0, 0)"> </font><span class="gmail-o" style="color:inherit;box-sizing:border-box;font-weight:bold">--</span><span class="gmail-n" style="color:inherit;box-sizing:border-box">x</span><span class="gmail-p" style="color:inherit;box-sizing:border-box">;</span><font color="rgba(0, 0, 0, 0)"> </font><span class="gmail-k" style="color:inherit;box-sizing:border-box;font-weight:bold">break</span><span class="gmail-p" style="color:inherit;box-sizing:border-box">;</span><font color="rgba(0, 0, 0, 0)"> </font><span class="gmail-c1" style="color:rgb(153,153,136);box-sizing:border-box;font-style:italic">// TODO warning: x and F3 have different types.
</span><font color="rgba(0, 0, 0, 0)"> </font><span class="gmail-p" style="color:inherit;box-sizing:border-box">}</span><font color="rgba(0, 0, 0, 0)">
</font><span class="gmail-k" style="color:inherit;box-sizing:border-box;font-weight:bold">if</span><font color="rgba(0, 0, 0, 0)"> </font><span class="gmail-p" style="color:inherit;box-sizing:border-box">(</span><span class="gmail-n" style="color:inherit;box-sizing:border-box">ee</span><font color="rgba(0, 0, 0, 0)"> </font><span class="gmail-o" style="color:inherit;box-sizing:border-box;font-weight:bold">==</span><font color="rgba(0, 0, 0, 0)"> </font><span class="gmail-n" style="color:inherit;box-sizing:border-box">F0</span><span class="gmail-p" style="color:inherit;box-sizing:border-box">)</span><font color="rgba(0, 0, 0, 0)"> </font><span class="gmail-p" style="color:inherit;box-sizing:border-box">{}</span><font color="rgba(0, 0, 0, 0)"> </font><span class="gmail-c1" style="color:rgb(153,153,136);box-sizing:border-box;font-style:italic">// Already exsisting warning: ee and F0 have different types.
</span><span class="gmail-c1" style="box-sizing:border-box"><font color="#000000"><b>if</b> (ee == x) {}</font></span><span class="gmail-c1" style="box-sizing:border-box"><i style="color:rgb(153,153,136)"> // Already exsisting warning: ee and x have different types.
</i><font color="#000000">}</font></span></code></pre></div><div style="font-size:12.8px">BR Alex.</div></div>