[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
Tue Jan 4 04:30:31 PST 2022


curdeius updated this revision to Diff 397265.
curdeius added a comment.

Reverted test changes. Checking for identifier before brace.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D116527/new/

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
@@ -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"
Index: clang/lib/Format/WhitespaceManager.cpp
===================================================================
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -362,6 +362,13 @@
             Changes[i].Tok->Previous->is(TT_ConditionalExpr))
           return true;
 
+        // Continued braced list.
+        if (ScopeStart > Start + 1 &&
+            Changes[ScopeStart - 2].Tok->isNot(tok::identifier) &&
+            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.397265.patch
Type: text/x-patch
Size: 1213 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220104/abb15d77/attachment.bin>


More information about the cfe-commits mailing list