<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/65315>65315</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-tidy] False positive bugprone-non-zero-enum-to-bool-conversion with custom operator
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
chrchr-github
</td>
</tr>
</table>
<pre>
~~~c++
enum E {
E0 = 0x1,
E1 = 0x2,
E2 = 0x4
};
E operator&(E a, E b) { return static_cast<E>(a & b); }
void f(E e) {
if (e & E1) {}
}
~~~
~~~
<[source>:10:9: warning: conversion of 'E' into 'bool' will always return 'true', enum doesn't have a zero-value enumerator [bugprone-non-zero-enum-to-bool-conversion]
10 | if (e & E1) {}
| ^
[<source>:1:6: note: enum is defined here]
1 | enum E {
| ^
~~~
https://godbolt.org/z/nv3PxYdM7
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVE2PozgQ_TXFpUQLbBzCgUM-4LbSXve0MqYCXjl2ZJtkeg757SvT6aSntdJOFGG7_Pzq1TOFDEFPlqgFsQdxzOQSZ-dbNXs1-3zScV6GbHDje3u_3xWwffoXRyh2ZJczdgj1Y42I2BUI_IjFjxLY4Uu4fITZr2H2CFcfMaiPwB9sH88O3YW8jM4D2wDbdiiBHbDDAViTUqOnuHiLIcqo1d9Khgj80AHvgG0lAtusUOB7TOxfqK9Oj3haOelB9lKmTwhsS-v5rvzcfhJ8Tu73-7cJ8AOIfXCLV5RE8F1ZAN81wHd4k95qO6WpcvZKPmhn0aVUdQesRm2jS4vBOZPWN20MSnOT7-GzTmB19AsBq5MP6xWMjoJNcZzllVDiT_Iuv0qz0Ar48A9B7IdlunhnKbfO5isq7efR5Slj_hIF4vj0oiwQ6gP-vytPWPqB6B6GiD3wwy-GAN9tkgnWRUrjWoUOONJJWxpxJk9fFWC5Uv_X-4avpM-Mz7uYY7wE4DtgPbB-cuPgTHxzfgLW_wTW2yv_88df4x_1BzwbWz42vJEZteWm4U0pqrrJ5rYqGC9KVW-LbcUqqpXabsSGTlUxVqdxs810yxKkKUTJioo3b7wWfJBcikIJVVIDVUFnqc2bMddzUpDpEBZqN4KXIjNyIBPWBmTM0g3XTWAs9aNv05l8WKYAVWF0iOHFEnU0a-cqI-2URz2-gzhiL00gvLigo74S_va1403HGdUSojs_Gy9bvGm_Wbl-Fd6UOwPrk5jHkF-8-4dUBNavJQRg_VrivwEAAP__bd9Dtg">