Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

clang-format adds bogus linebreak when function arguments contain lambda #44111

Open Quuxplusone opened 4 years ago

Quuxplusone commented 4 years ago
Bugzilla Link PR45141
Status CONFIRMED
Importance P normal
Reported by Nikos Chantziaras (realnc@gmail.com)
Reported on 2020-03-07 03:49:34 -0800
Last modified on 2021-09-09 03:27:41 -0700
Version 10.0
Hardware PC Linux
CC clemenswerther@gmail.com, curdeius@gmail.com, djasper@google.com, klimek@google.com, llvm-bugs@lists.llvm.org, mario@emmenlauer.de
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
clang-format is unable to correctly format code like this:

  func(0, [] {}, 0);

It will format it into:

  func(
      0, [] {}, 0);

Shortest example code that reproduces it:

  void f()
  {
      func(0, [] {}, 0);
  }

The clang-format invocation can be the simplest possible. Just "clang-format
test.cpp" without any .clang-format input file and no arguments.
Quuxplusone commented 4 years ago

It only happens when the lambda is neither the first nor the last argument.

Quuxplusone commented 4 years ago

That's a regression between clang-format 7(.1) and 8.

Quuxplusone commented 4 years ago

This behaviour was caused by commit 5528cace0402a57564a4b541dcce755a27737d51 ([clang-format] tweaked another case of lambda formatting). Reverting this commit makes the testcases from this PR pass.

The mentioned commit introduced an aggressive way of breaking lines when lambda is not the last arguments.