================
@@ -4249,11 +4253,40 @@ FormatToken 
*TokenAnnotator::calculateInitializerColumnList(
       ++Depth;
     else if (CurrentToken->is(tok::r_brace))
       --Depth;
+
+    // Ensure each outer array element starts on its own line
+    if (Depth == 1 && CurrentToken->is(tok::comma)) {
+      auto *NextNonComment = CurrentToken->getNextNonComment();
+      if (NextNonComment)
+        NextNonComment->MustBreakBefore = true;
+    }
+
     if (Depth == 2 && CurrentToken->isOneOf(tok::l_brace, tok::comma)) {
       CurrentToken = CurrentToken->Next;
       if (!CurrentToken)
         break;
-      CurrentToken->StartsColumn = true;
+
+      // Right (closing) braces should not count as starting a column because
+      // they are aligned using separate logic.
+
+      // Note: This uses startsSequence() so that trailing comments are skipped
+      // when checking if the token after a comma/l-brace is a r_brace. We 
can't
+      // just ignore comments in general, because an inline comment with
+      // something else after it should still count as starting a column.
+      // IE:
+      //
+      //        { // a
+      //          4
+      //        }
+      //
+      //   vs.
+      //
+      //        { /* a */ 4 }
+      //
----------------
HazardyKnusperkeks wrote:

Maybe put this next to each other, to not waste as much vertical space.

https://github.com/llvm/llvm-project/pull/143781
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to