<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/125724>125724</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang-tidy misc-no-recursion check should not diagnose tail recursion
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-tidy
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
danakj
</td>
</tr>
</table>
<pre>
The `[[clang::musttail]]` attribute ensures that a recursive call does not add a stack frame. It should not be diagnosed by misc-no-recursion.
https://godbolt.org/z/1WebxfofP
```cc
int tail_recursive(int a) {
if (a > 0) {
return a;
} else {
[[clang::musttail]] return tail_recursive(2);
}
}
```
```
[<source>:1:5: warning: function 'tail_recursive' is within a recursive call chain [misc-no-recursion]](javascript:;)
1 | int tail_recursive(int a) {
| ^
[<source>:1:5: note: example recursive call chain, starting from function 'tail_recursive'](javascript:;)
[<source>:5:36: note: Frame #1: function 'tail_recursive' calls function 'tail_recursive' here:](javascript:;)
5 | [[clang::musttail]] return tail_recursive(2);
| ^
[<source>:5:36: note: ... which was the starting point of the recursive call chain; there may be other cycles](javascript:;)
1 warning generated.
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJykVE9vqzgQ_zTDZRRk7BDIgQNpG2lve1hpjytjBnBr7Mg27ct--pVJ03abt-1KL0JxYobx78_wkyHo0RI1UB6gvM_kEifnm15a-fSYda4_N39MhLBja8FBGWlHEC2Idl5CjFIbKO_TtWMoY_S6WyIh2bB4ChgnGVGiJ7X4oJ8JlTQGe0cBrYso-x4lhijVEw5ezpTjbxHD5BbTrwUdYa_laF2gHrszzjqojXWb14bO5sBaYO0U4ykkWPwI_Di6vnMm5s6PwI9_Az8Wf1L3Y3DD75fyRGe9lALWahsxEfnrDSbwOm1K4HuE6gCsRUTUAwKvJYJ4QPbvW-njKS7eogRx3YXqHskEuhZ-I-G1ww0WDnz_2hWq-4T_8n1l8fl3eQBxF9ziFYF4ANEWINoSRIsv0lu9no7DYlXUziLw6vOJFeqALzpO2t66pyapbeJyY8brJPD6UT7LoLw-xZXnIeG_SFIgVHf4fxXHtXpdy4evmVkXKa30Q84nQz8FDfwuDZuP2o44eDd_LcJXXG6RJBRi9xHKMU00AhfF93onkOGbmol86vudxOWbaBfhfnnm3oz4LxNuqed5ji-TVhO-yJQC9K77ySWj3bDu_tQlcUj3POEszykBXPqH6qwMha_IF9fxxpEseRmpzz--GlnfiH4v9jKjpqhEvav3e86yqZFFSXWtiu2uKKgeyh3rWF_VXJSsFHuxz3TDGS8ZZ9ui4iVnec2ISDFVVt1QcCZhy2iW2uTGPM8pdzIdwkJNwcuKbzMjOzJhzVjOVy82Ufdn4Dxlrm_SU5tuGQNsmdEhhvc-UUdDzfsztxGIaiL19DE1r5G5uopvhdniTfMpKXWcli5XbgZ-TGe-LpuTd4-kIvDjSiSkDL1weW74PwEAAP__3T7obw">