[clang-tools-extra] [clang-tidy] Add parameter clause in use-trailing-return-type lambda fixes (PR #240116)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Nov 8 02:57:29 PST 2026
https://github.com/awrrrr created https://github.com/llvm/llvm-project/pull/240116
Omitting the parameter clause before a trailing return type is only valid since C++23 (P1102R2), but `modernize-use-trailing-return-type` rewrote `[] { return 1; }` to `[] -> int { return 1; }` in every language mode. Before C++23, clang then warns `lambda without a parameter clause is a C++23 extension`, so a `-Werror` or `-pedantic-errors` build breaks after `--fix`.
Before C++23, the check now inserts `() -> T` after the lambda introducer, or after the template parameter list, when the body follows directly:
```cpp
// Before C++23, before:
auto a = [] -> int { return 1; };
auto b = []<typename T = int> -> auto { return T{}; };
// Before C++23, after:
auto a = []() -> int { return 1; };
auto b = []<typename T = int>() -> auto { return T{}; };
```
If specifiers, a `requires` clause or a macro come between the introducer and the body, the `()` would have to go somewhere else, so the check keeps the warning but doesn't offer a fix. C++23 and later are unchanged.
Tests: the new `use-trailing-return-type-transform-lambdas-no-parameter-clause.cpp` covers C++11 through C++23. In `use-trailing-return-type-transform-lambdas.cpp`, which runs in all modes, the lambdas without a parameter clause now have `()`, so they keep testing the return-type printing; `l01` is covered by the new file.
Fixes #237693
I used Claude Code to help write this change, and I have reviewed all of it myself.
Assisted-by: Claude Code
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<html><body><h1>504 Gateway Time-out</h1>
The server didn't respond in time.
</body></html>
More information about the cfe-commits
mailing list