<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/96298>96298</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
bugprone-branch-clone false positive in if else if chains with other branches inbetween
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
lukas-lang
</td>
</tr>
</table>
<pre>
The following warns about duplicated branches (https://godbolt.org/z/M4WMxxqfs):
```cpp
int test2(int);
void test1(bool a, bool b, bool c) {
if (a)
test2(1);
else if (b)
test2(0);
else if (c)
test2(1);
}
```
Of course, I could rewrite it as follows, but this repeats the conditions, so it's not really better. On the contrary, this will become worse if more branches are in between the repeated ones, and negating the conditions properly can also be confusing to get right:
```cpp
int test2(int);
void test1(bool a, bool b, bool c) {
if (a || (!b && c))
test2(1);
else if (b)
test2(0);
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEVE1v2zgQ_TXUZWBDoj8kHXTYJDCwhyCXBfZMUiOJLc1RyZEd99cXlOw4TdH2UqCGIQ3I92bmkU-jYrS9R2zE7kHsnjI18UChcdNnFVdO-T7T1F6a_waEjpyjs_U9nFXwEZSmiaGdRmeNYmxBB-XNgBGErAbmMYrNP0IehDz01GpyvKbQC3n4KuThefv_8-vrly4KWSdY_iTy23OfL38zjsuK9QyMkaWQlfU8Ux7eU05k2xlRCFlpIgdKyEeYI_0WGSFrEOWVCQBgu9SrSgmXtVuV4n2NhEQX8QrXd_j1d2Plv2CZ3xQR5dMH-e8FvnRgaAoRk5h_U-xaCHgOlhEsg4rX64mz2omBBxsh4IiKI_CAYMi3li35GRIJLAtZRvDEEFA5dwGNzBjW8OJvDA4qXBJ-Tne2zoFGQ0eEM4VF25EC3q9eBQTrU6Yz4pJmaQJbII9zbeVb8NgrTl76vjUYA40Y3AWM8qBcJNDzfjfFGU3QI0Ow_cB_3TYgykdRPqZYyEKDkHsh9zP-pxb5A8b60SlZ22zaelOrDJuiLKp6X5X1JhuaXSXbbbfTRueFQqXqTd3qYmN0uUUsc5PZRuZym-9lURRFvcvXRaU3eVljYfK97mottjkelXVr507H9P1mNsYJm3ov6ypzSqOL8-yQ0uMZ5k0hZRoloUmclZ76KLa5s5HjPQtbdtjoqR8DeVwt_lkZRx6hU-lMRoqW7Wm2k-3ezskMyvpkRR6AeMBw9571V9tlU3DNhwlkeZj02tBRyEPq4vpajYE-oWEhD3PvUcjDou3UyG8BAAD__wmbhxw">