[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:58:31 PST 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-tidy
@llvm/pr-subscribers-clang-tools-extra
Author: awrrrr
<details>
<summary>Changes</summary>
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)
---
Full diff: https://github.com/llvm/llvm-project/pull/240116.diff
4 Files Affected:
- (modified) clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp (+38)
- (modified) clang-tools-extra/docs/ReleaseNotes.md (+5)
- (added) clang-tools-extra/test/clang-tidy/checkers/modernize/use-trailing-return-type-transform-lambdas-no-parameter-clause.cpp (+62)
- (modified) clang-tools-extra/test/clang-tidy/checkers/modernize/use-trailing-return-type-transform-lambdas.cpp (+4-8)
``````````diff
<html><body><h1>504 Gateway Time-out</h1>
The server didn't respond in time.
</body></html>
``````````
</details>
https://github.com/llvm/llvm-project/pull/240116
More information about the cfe-commits
mailing list