From 2fc2ee136c0183f40af4c0e7a8d27092b8ce3415 Mon Sep 17 00:00:00 2001 From: XDeme <66138117+XDeme@users.noreply.github.com> Date: Sat, 20 Jan 2024 18:34:37 -0300 Subject: [clang-format] Fix poor spacing in `AlignArrayOfStructures: Left` (#77868) Fixes llvm/llvm-project#62904 `AlignArrayOfStructures: Left` combined with `SpacesInParentheses: true` causes the first cell of every row to have 1 additional space. We were only setting the first cell of the first row to be against the left brace, now every row will be against the left brace. --- clang/lib/Format/WhitespaceManager.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'clang/lib/Format/WhitespaceManager.cpp') diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp index 8415c8d..df84f97 100644 --- a/clang/lib/Format/WhitespaceManager.cpp +++ b/clang/lib/Format/WhitespaceManager.cpp @@ -1366,11 +1366,12 @@ void WhitespaceManager::alignArrayInitializersLeftJustified( auto &Cells = CellDescs.Cells; // Now go through and fixup the spaces. auto *CellIter = Cells.begin(); - // The first cell needs to be against the left brace. - if (Changes[CellIter->Index].NewlinesBefore == 0) - Changes[CellIter->Index].Spaces = BracePadding; - else - Changes[CellIter->Index].Spaces = CellDescs.InitialSpaces; + // The first cell of every row needs to be against the left brace. + for (const auto *Next = CellIter; Next; Next = Next->NextColumnElement) { + auto &Change = Changes[Next->Index]; + Change.Spaces = + Change.NewlinesBefore == 0 ? BracePadding : CellDescs.InitialSpaces; + } ++CellIter; for (auto i = 1U; i < CellDescs.CellCounts[0]; i++, ++CellIter) { auto MaxNetWidth = getMaximumNetWidth( -- cgit v1.1