[PATCH] D115972: [clang-format] Fix AlignConsecutiveAssignments breaking lambda formatting.

Marek Kurdej via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 17 14:32:29 PST 2021


curdeius created this revision.
curdeius added reviewers: MyDeveloperDay, HazardyKnusperkeks, owenpan.
curdeius requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fixes https://github.com/llvm/llvm-project/issues/52772.

This patch fixes the formatting of the code:

  auto aaaaaaaaaaaaaaaaaaaaa = {};
  auto b                     = g([] {
    return;
  });

which should be left as is, but before this patch was formatted to:

  auto aaaaaaaaaaaaaaaaaaaaa = {};
  auto b                     = g([] {
    return;
                      });


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115972

Files:
  clang/lib/Format/WhitespaceManager.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -16110,6 +16110,13 @@
                    "int yy  = 1; ///specificlennospace\n"
                    "int zzz = 2;\n",
                    Alignment));
+
+  Alignment.AllowShortLambdasOnASingleLine = FormatStyle::SLS_None;
+  verifyFormat("auto aaaaaaaaaaaaaaaaaaaaa = {};\n"
+               "auto b                     = g([] {\n"
+               "  return;\n"
+               "});",
+               Alignment);
 }
 
 TEST_F(FormatTest, AlignConsecutiveBitFields) {
Index: clang/lib/Format/WhitespaceManager.cpp
===================================================================
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -346,8 +346,12 @@
         // Continued function call
         if (ScopeStart > Start + 1 &&
             Changes[ScopeStart - 2].Tok->is(tok::identifier) &&
-            Changes[ScopeStart - 1].Tok->is(tok::l_paren))
+            Changes[ScopeStart - 1].Tok->is(tok::l_paren)) {
+          if (Changes[i].Tok->MatchingParen &&
+              Changes[i].Tok->MatchingParen->is(TT_LambdaLBrace))
+            return false;
           return Style.BinPackArguments;
+        }
 
         // Ternary operator
         if (Changes[i].Tok->is(TT_ConditionalExpr))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115972.395223.patch
Type: text/x-patch
Size: 1429 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211217/820f5893/attachment.bin>


More information about the cfe-commits mailing list