Skip to content

clang-format set short lambda max length? #143877

Open
@Vladislav-Bartalevich

Description

@Vladislav-Bartalevich

Is it possible to set a maximum length for short lambdas?

In my project, I have a ColumnLimit: 0 and I want to achieve two things:

  • Short lambdas should stay on a single line (so I have AllowShortLambdasOnASingleLine: All)
  • Allman-style line breaks before braces for long lambdas (so I have BreakBeforeBraces: Allman)

However, it seems that clang-format uses a default maximum line length of 90 characters for short lambdas. When the line length reaches or exceeds 90, clang-format always introduces a line break.

From a code formatting perspective, I want this:

auto SomeLongOneLiner = [](int SomeLongPieceOfCodeHere) { return SomeLongPieceOfCodeHere != 2; };  // 114 characters

To remain on a single line as shown above. But when I run the formatter, it transforms the code into:

auto SomeLongOneLiner = [](int SomeLongPieceOfCodeHere)
{ return SomeLongPieceOfCodeHere != 2; };

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions