[clang] [clang-format] add option to control bin-packing keyworded parameters (PR #131605)

Björn Schäpers via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 18 14:48:10 PDT 2025


================
@@ -29096,6 +29096,63 @@ TEST_F(FormatTest, BreakBeforeClassName) {
                "    ArenaSafeUniquePtr {};");
 }
 
+TEST_F(FormatTest, FunctionDeclarationWithKeywords) {
+  FormatStyle::FunctionDeclarationWithKeywords QPropertyDeclaration;
+  QPropertyDeclaration.Name = "Q_PROPERTY";
+  QPropertyDeclaration.Keywords.push_back("READ");
+  QPropertyDeclaration.Keywords.push_back("WRITE");
+  QPropertyDeclaration.Keywords.push_back("NOTIFY");
+  QPropertyDeclaration.Keywords.push_back("RESET");
+
+  auto Style40 = getLLVMStyleWithColumns(40);
+  Style40.FunctionDeclarationsWithKeywords.push_back(QPropertyDeclaration);
+  Style40.BinPackParameters = FormatStyle::BPPS_OnePerLine;
+
+  verifyFormat(
+      "Q_PROPERTY(int name\n"
+      "           READ name\n"
+      "           WRITE setName\n"
+      "           NOTIFY nameChanged)",
+      "Q_PROPERTY(int name READ name WRITE setName NOTIFY nameChanged)",
+      Style40);
----------------
HazardyKnusperkeks wrote:

```suggestion
  verifyFormat(
      "Q_PROPERTY(int name\n"
      "           READ name\n"
      "           WRITE setName\n"
      "           NOTIFY nameChanged)",
      Style40);
```

`verifyFormat` has different runs, one of them removes all unneeded whitespace and line endings.

https://github.com/llvm/llvm-project/pull/131605


More information about the cfe-commits mailing list