-
Notifications
You must be signed in to change notification settings - Fork 10.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clang-format] Fix poor spacing in AlignArrayOfStructures: Left
#77868
Conversation
Fixes llvm#62904 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.
@llvm/pr-subscribers-clang-format Author: None (XDeme) ChangesFixes llvm/llvm-project#62904 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. Full diff: https://github.com/llvm/llvm-project/pull/77868.diff 2 Files Affected:
diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp
index f1d176f182ffa4..d91a212d357689 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)
+ if (Changes[Next->Index].NewlinesBefore == 0)
+ Changes[Next->Index].Spaces = BracePadding;
+ else
+ Changes[Next->Index].Spaces = CellDescs.InitialSpaces;
++CellIter;
for (auto i = 1U; i < CellDescs.CellCounts[0]; i++, ++CellIter) {
auto MaxNetWidth = getMaximumNetWidth(
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 8f115fb8cbf0fb..4d44a1f0a9ff97 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -21325,6 +21325,14 @@ TEST_F(FormatTest, CatchAlignArrayOfStructuresLeftAlignment) {
"00000000000000000000000000000000000000000000000000000000\" },\n"
"};",
Style);
+
+ Style.SpacesInParens = FormatStyle::SIPO_Custom;
+ Style.SpacesInParensOptions.Other = true;
+ verifyFormat("Foo foo[] = {\n"
+ " {1, 1},\n"
+ " {1, 1},\n"
+ "};",
+ Style);
}
TEST_F(FormatTest, UnderstandsPragmas) {
|
@HazardyKnusperkeks ping |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, seems I've missed this change.
Co-authored-by: Owen Pan <owenpiano@gmail.com>
✅ With the latest revision this PR passed the C/C++ code formatter. |
Fixes #62904
AlignArrayOfStructures: Left
combined withSpacesInParentheses: 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.