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

Owen Pan via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 13 14:16:50 PST 2023


https://github.com/owenca created https://github.com/llvm/llvm-project/pull/72166

Fixed #68431.

>From 7442d202cdd0e22dba178731be01517aa8257d40 Mon Sep 17 00:00:00 2001
From: Owen Pan <owenpiano at gmail.com>
Date: Mon, 13 Nov 2023 14:04:32 -0800
Subject: [PATCH] [clang-format] Skip alignArrayInitializers() for 1-row
 matrices

Fixed #68431.
---
 clang/lib/Format/WhitespaceManager.h  | 2 +-
 clang/unittests/Format/FormatTest.cpp | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

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"



More information about the cfe-commits mailing list