diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp --- a/clang/lib/Format/WhitespaceManager.cpp +++ b/clang/lib/Format/WhitespaceManager.cpp @@ -1168,6 +1168,10 @@ auto MaxNetWidth = getMaximumNetWidth( Cells.begin(), CellIter, CellDescs.InitialSpaces, CellDescs.CellCounts[0], CellDescs.CellCounts.size()); + // If Cpp11BraceListStyle is false, the braces need to be space-separated from + // the elements. + if (!Style.Cpp11BracedListStyle) + MaxNetWidth += 1; if (ThisNetWidth < MaxNetWidth) Changes[CellIter->Index].Spaces = (MaxNetWidth - ThisNetWidth); auto RowCount = 1U; @@ -1186,9 +1190,10 @@ auto ThisWidth = calculateCellWidth(CellIter->Index, CellIter->EndIndex, true) + NetWidth; + auto BeginSpace = (i > 0) ? 1 : (Style.Cpp11BracedListStyle ? 0 : 1); if (Changes[CellIter->Index].NewlinesBefore == 0) { Changes[CellIter->Index].Spaces = (CellWidth - (ThisWidth + NetWidth)); - Changes[CellIter->Index].Spaces += (i > 0) ? 1 : 0; + Changes[CellIter->Index].Spaces += BeginSpace; } alignToStartOfCell(CellIter->Index, CellIter->EndIndex); for (const auto *Next = CellIter->NextColumnElement; Next; @@ -1197,7 +1202,7 @@ calculateCellWidth(Next->Index, Next->EndIndex, true) + NetWidth; if (Changes[Next->Index].NewlinesBefore == 0) { Changes[Next->Index].Spaces = (CellWidth - ThisWidth); - Changes[Next->Index].Spaces += (i > 0) ? 1 : 0; + Changes[Next->Index].Spaces += BeginSpace; } alignToStartOfCell(Next->Index, Next->EndIndex); } @@ -1214,9 +1219,10 @@ 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. + // The first cell needs to be against the left brace, unless + // Cpp11BracedListStyle is enabled. if (Changes[CellIter->Index].NewlinesBefore == 0) - Changes[CellIter->Index].Spaces = 0; + Changes[CellIter->Index].Spaces = Style.Cpp11BracedListStyle ? 0 : 1; else Changes[CellIter->Index].Spaces = CellDescs.InitialSpaces; ++CellIter; @@ -1229,7 +1235,9 @@ if (Changes[CellIter->Index].NewlinesBefore == 0) { Changes[CellIter->Index].Spaces = MaxNetWidth - ThisNetWidth + - (Changes[CellIter->Index].Tok->isNot(tok::r_brace) ? 1 : 0); + (Changes[CellIter->Index].Tok->isNot(tok::r_brace) + ? 1 + : (Style.Cpp11BracedListStyle ? 0 : 1)); } auto RowCount = 1U; auto Offset = std::distance(Cells.begin(), CellIter); @@ -1243,7 +1251,9 @@ if (Changes[Next->Index].NewlinesBefore == 0) { Changes[Next->Index].Spaces = MaxNetWidth - ThisNetWidth + - (Changes[Next->Index].Tok->isNot(tok::r_brace) ? 1 : 0); + (Changes[Next->Index].Tok->isNot(tok::r_brace) + ? 1 + : (Style.Cpp11BracedListStyle ? 0 : 1)); } ++RowCount; }