Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

clang-format: ColumnLimit:0 breaks lambda formatting #49900

Open Quuxplusone opened 3 years ago

Quuxplusone commented 3 years ago
Bugzilla Link PR50931
Status CONFIRMED
Importance P normal
Reported by Vadim Kalinnikov (kalinnikov@seaproject.ru)
Reported on 2021-06-29 06:09:22 -0700
Last modified on 2021-07-07 02:16:46 -0700
Version 12.0
Hardware PC Linux
CC djasper@google.com, klimek@google.com, llvm-bugs@lists.llvm.org, mydeveloperday@gmail.com
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
Setting ColumnLimit to 0 causes clang-format to add an extra line break between
[] and { for a single-line lambda.

---
test.cpp:
int main() {
  std::vector<int> v;
  std::find_if(v.begin(), v.end(), [] {return 1;});
}

---
.clang-format:
BreakBeforeBraces: Custom
BraceWrapping:
  BeforeLambdaBody: true
ColumnLimit: 0

clang-format test.cpp:
int main() {
  std::vector<int> v;
  std::find_if(v.begin(), v.end(), []
               { return 1; });
}

---
.clang-format:
BreakBeforeBraces: Custom
BraceWrapping:
  BeforeLambdaBody: true

clang-format test.cpp:
int main() {
  std::vector<int> v;
  std::find_if(v.begin(), v.end(), [] { return 1; });
}
Quuxplusone commented 3 years ago

I don't know if there is a cause other than that you've said you want to break before the {

also in the documentation it does say

A column limit of 0 means that there is no column limit. In this case, clang-format will respect the input’s line breaking decisions within statements unless they contradict other rules.

Emphasis on the "unless they contradict other rules"

I'm not sure if this classes as one of those other rules

Quuxplusone commented 3 years ago
Such behavior is inconsistent with some other rules.
For functions breaking doesn't happen if I put everything on a single line, so
I reckon neither should it happen for lambdas.
Quuxplusone commented 3 years ago

Maybe looks at AllowShortLambdasOnASingleLine

Quuxplusone commented 3 years ago

Yes, AllowShortLambdasOnASingleLine would fix the issue.