[Development] proposed clang-format improvements for lambda functions
Tim Blechmann
tim.blechmann at qt.io
Wed Oct 8 02:45:37 CEST 2025
i'd like to propose the following improvements to the clang-format:
AllowShortLambdasOnASingleLine: None
LambdaBodyIndentation: OuterScope
rationale:
* single-line lambda functions are harmful, as one cannot set different
breakpoints for construction and invocation of the lambda function.
* indent lambda bodies at the outer scope, so that the indentation
reflects the nesting level.
currently we get:
> void foo(auto);
>
> void bar()
> {
> return foo([] { foo([] { return 0; }); });
> }
>
> void foooo(int, auto);
>
> void baz()
> {
> return foooo(0, [] {
> foo([] {
> auto x = 1 + 1;
> return x;
> });
> });
>
> return foooo(
> iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiint,
> [] {
> foo([] {
> auto x = 1 + 1;
> return x;
> });
> });
> }
after the proposed changes, we'd end up with:
> void foo(auto);
>
> void bar()
> {
> return foo([] {
> foo([] {
> return 0;
> });
> });
> }
>
> void foooo(int, auto);
>
> void baz()
> {
> return foooo(0, [] {
> foo([] {
> auto x = 1 + 1;
> return x;
> });
> });
>
> return foooo(
> iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiint,
> [] {
> foo([] {
> auto x = 1 + 1;
> return x;
> });
> });
> }
opinions?
More information about the Development
mailing list