Skip to content

[clang-format][NFC] Skip alignArrayInitializers() for 1-row matrices #72166

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

Merged
merged 2 commits into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/lib/Format/WhitespaceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ class WhitespaceManager {
// Determine if every row in the array
// has the same number of columns.
bool isRectangular() const {
if (CellCounts.empty())
if (CellCounts.size() < 2)
return false;

for (auto NumberOfColumns : CellCounts)
Expand Down
4 changes: 3 additions & 1 deletion clang/unittests/Format/FormatTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20875,13 +20875,15 @@ TEST_F(FormatTest, CatchAlignArrayOfStructuresRightAlignment) {
"};",
Style);
// TODO: Fix the indentations below when this option is fully functional.
#if 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it's wrong as the TODO comment says.

This patch doesn't fix it and would format it as:

int a[][] = {
    {
     {0, 2}, //
        {1, 2}  //
    }
};

Nevertheless, I just changed it to what it ought to look like.

verifyFormat("int a[][] = {\n"
" {\n"
" {0, 2}, //\n"
" {1, 2} //\n"
" {1, 2} //\n"
" }\n"
"};",
Style);
#endif
Style.ColumnLimit = 100;
verifyFormat(
"test demo[] = {\n"
Expand Down