<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/108846>108846</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-tidy] `readability-redundant-casting` false positive on inheritance
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-tidy
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
felix642
</td>
</tr>
</table>
<pre>
The following code snippet will trigger `readability-redundant-casting` and suggests removing the `static_cast`. Doing so would lead to a compilation failure.
```
class A
{
int a;
};
class B : public A
{
};
int main()
{
A a;
B b = static_cast<B>(a); // [warning: redundant explicit casting to the same type 'B' as the sub-expression, remove this casting [readability-redundant-casting]]
}
```
Godbolt : https://godbolt.org/z/qY1v196qG
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMk8-OozgQxp-muJQSGZu_Bw6hs-kX2MueVgYqUCvHprFJOvv0IyeZ7mimZzSSJWx9fJ9dv1Jp73m0RA3kLeT7RK9hcktzJMPvRSaTzg3X5u-J8OiMcRe2I_ZuIPSW55kCXtgYDAuPIy0IhVhID7pjw-G6WWhY7aBt2PTaB7YjFAK1HdCv40g-eFzo5M4xM0wU3T7owP2_8XcoxBb3Lore4cWtZkBDesDgUGPvTjMbHdhZPGo260JbEHsQOyjEY92OvdHe4-6hle19g4jINqAG1X6X9p_7J2eLoHY4r53h_qeYX1lj9EmzBVmBrL-4e_d0czy32CGoPT7Xr15aUH-BrHTMUC0iyAPIA0LeXvRiI0-1ww_ISO-z4Z4DPmhHUpGr1yfCcJ0JQZYtyBK1vwtrt6H3eSHv2VmQL_d-EIaJ_UcK5O3vm5rv4_pA8VUXXt3QORNuLKcQZg9qd69mvCtbt4wgD_-DPLz9k57Tunh7vVuToVFDrWqdUJOWssiFqESdTI0QWXUkkZVdoYaqy9Ki0nUlu4pIVbVQCTdSyEzUaZHmSslqW1ayL0RWqLzs5ZCWkAk6aTZbY86n-IKEvV-pSUVVZUVidEfG3wZDyt5oO24CD1eQMg7K0kTXpltHD5kw7IP_zAkczG2knmz5_o_m46iNJ5yd58BnQmeR7UQLB217StbFND8A5DCt3bZ3J5CH-IDHZzMv7j_qA8jDrSoP8vAo7NzIbwEAAP__wFA2vw">