[PATCH] D116527: [clang-format] Fix indentation for array variables with alignment of consecutive assignments and declarations.

Marek Kurdej via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 3 01:41:51 PST 2022


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/52914.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116527

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
@@ -15170,9 +15170,9 @@
                "int   i  = 0;\n"
                "float i2 = 0;\n"
                "auto  v  = type{\n"
-               "    i = 1,   //\n"
-               "    (i = 2), //\n"
-               "    i = 3    //\n"
+               "      i = 1,   //\n"
+               "      (i = 2), //\n"
+               "      i = 3    //\n"
                "};",
                Style);
 
@@ -16402,6 +16402,11 @@
                "  double        bar();\n"
                "};\n",
                Alignment);
+  // http://llvm.org/PR52914
+  verifyFormat("char *a[]     = {\"a\", // comment\n"
+               "                 \"bb\"};\n"
+               "int   bbbbbbb = 0;",
+               Alignment);
 
   // PAS_Right
   EXPECT_EQ("void SomeFunction(int parameter = 0) {\n"
@@ -16660,9 +16665,9 @@
                "int   i  = 0;\n"
                "float i2 = 0;\n"
                "auto  v  = type{\n"
-               "    i = 1,   //\n"
-               "    (i = 2), //\n"
-               "    i = 3    //\n"
+               "      i = 1,   //\n"
+               "      (i = 2), //\n"
+               "      i = 3    //\n"
                "};",
                Alignment);
   Alignment.AlignConsecutiveAssignments = FormatStyle::ACS_None;
Index: clang/lib/Format/WhitespaceManager.cpp
===================================================================
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -362,6 +362,11 @@
             Changes[i].Tok->Previous->is(TT_ConditionalExpr))
           return true;
 
+        // Continued braced list.
+        if (Changes[ScopeStart - 1].Tok->is(tok::l_brace) &&
+            Changes[i].Tok->isNot(tok::r_brace))
+          return true;
+
         return false;
       };
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116527.397022.patch
Type: text/x-patch
Size: 1972 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220103/8551b6b5/attachment.bin>


More information about the cfe-commits mailing list