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

Conversation

owenca
Copy link
Contributor

@owenca owenca commented Nov 13, 2023

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Nov 13, 2023

@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)

Changes

Fixed #68431.


Full diff: https://github.com/llvm/llvm-project/pull/72166.diff

2 Files Affected:

  • (modified) clang/lib/Format/WhitespaceManager.h (+1-1)
  • (modified) clang/unittests/Format/FormatTest.cpp (+2)
diff --git a/clang/lib/Format/WhitespaceManager.h b/clang/lib/Format/WhitespaceManager.h
index df7e9add1cd446f..42af671c16586f7 100644
--- a/clang/lib/Format/WhitespaceManager.h
+++ b/clang/lib/Format/WhitespaceManager.h
@@ -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)
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index f531e6da6a5c31b..849f70e5295b36e 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -20875,6 +20875,7 @@ TEST_F(FormatTest, CatchAlignArrayOfStructuresRightAlignment) {
                "};",
                Style);
   // TODO: Fix the indentations below when this option is fully functional.
+#if 0
   verifyFormat("int a[][] = {\n"
                "    {\n"
                "     {0, 2}, //\n"
@@ -20882,6 +20883,7 @@ TEST_F(FormatTest, CatchAlignArrayOfStructuresRightAlignment) {
                "    }\n"
                "};",
                Style);
+#endif
   Style.ColumnLimit = 100;
   verifyFormat(
       "test demo[] = {\n"

@@ -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.

@owenca owenca changed the title [clang-format] Skip alignArrayInitializers() for 1-row matrices [clang-format][NFC] Skip alignArrayInitializers() for 1-row matrices Nov 17, 2023
@owenca owenca merged commit e16a834 into llvm:main Nov 19, 2023
@owenca owenca deleted the 68431 branch November 19, 2023 22:58
sr-tream pushed a commit to sr-tream/llvm-project that referenced this pull request Nov 20, 2023
zahiraam pushed a commit to zahiraam/llvm-project that referenced this pull request Nov 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants