<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/93491>93491</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang-tidy readability-else-after-return is not compatible with C++17 if init-statements
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-tidy
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
matiaslindgren
</td>
</tr>
</table>
<pre>
The following code emits a false positive warning on trunk clang-tidy.
```c++
int f();
int g() {
if (auto x{f()}; x > 0) {
return x;
} else {
return -x;
}
}
```
`x` does not exist outside the scope of the `if` and `else` branches so the `else` branch cannot be removed in this case. Moving the init-statement outside the `if` statement would change the logic too much because `x` lives now in the outer scope.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx0Us2uszYQfRqzGRGBgQALFl-aZtddX8DYA0xr7Mgekty3rxxyk15VjSyF-Tkz52iOipFmhziI5iSac6Y2XnwYVsWkoiVn5oAuG735Gv5cECZvrb-Tm0F7g4ArcQQFk7IR4eojMd0Q7iq41OMdcNjc36CtcnPOZL4OojiL4pc4FvvTQp7Se2bJMUxCdkL2onrlPpV5r4BoXyUAAJpAyE5t7OEh2tM3uj2L6gQPENXvUPwHlH4BeQsOHu9FKSnaM2CS8n_t-b_605Kd4vvjW9U7fIhjAcZjBOcZ8EGRwW8cySDwghC1vyL46RmIY0FTAihnUpCYpHAMyukFI0T_3fezBFq5NH9ECLj6GxogB7xQBK0iHuAPf0v3SGByxHlkxbii-0nmvf9TvvvNGtCLcvPeY_1MGth7WDe9wIhabfEJfUq1dHtqve8EMM3HsMs8ZGaoTF_1KsOhbMtjV9edbLNl6LAt-1pOSpum6JqmGqXUnUFV9k1btZjRIAtZF41sZSkL2R6aetSm7ru-lM0Rp0LUBa6K7MHa23rwYc4oxg2Hvqr7MrNqRBufFpfy40UhZbJ8GBIoH7c5irqwFDl-xjCxxeGDgYDKqJEs8VeerpCriTHkL3_Qfmjt16tiGi3CnXiB33aXl23y688LxGwLdliYr1FUv4S8CHmZiZdtPGi_CnlJVF5_-TX4v1CzkJenvCjkZVd4G-Q_AQAA__8e2Cyk">