aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Format/WhitespaceManager.cpp
diff options
context:
space:
mode:
authorXDeme <66138117+XDeme@users.noreply.github.com>2024-01-20 18:34:37 -0300
committerGitHub <noreply@github.com>2024-01-20 13:34:37 -0800
commit2fc2ee136c0183f40af4c0e7a8d27092b8ce3415 (patch)
tree4e63ec86b280319d4d36d5730c246e6c55a1255e /clang/lib/Format/WhitespaceManager.cpp
parent85a8e5c3e0586e85a2fa3ff9cef12455bd039921 (diff)
downloadllvm-2fc2ee136c0183f40af4c0e7a8d27092b8ce3415.zip
llvm-2fc2ee136c0183f40af4c0e7a8d27092b8ce3415.tar.gz
llvm-2fc2ee136c0183f40af4c0e7a8d27092b8ce3415.tar.bz2
[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.
Diffstat (limited to 'clang/lib/Format/WhitespaceManager.cpp')
-rw-r--r--clang/lib/Format/WhitespaceManager.cpp11
1 files changed, 6 insertions, 5 deletions
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(