Issue 125724
Summary clang-tidy misc-no-recursion check should not diagnose tail recursion
Labels clang-tidy
Assignees
Reporter danakj
    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.
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to