[clang] [clang-format]: Add `Custom` to `ShortFunctionStyle`; add new AllowShortFunctionsOnASingleLineOptions for granular setup (PR #134337)

via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 9 19:29:53 PDT 2025


================
@@ -1959,6 +1964,52 @@ the configuration (without a prefix: ``Auto``).
       };
       void f() { bar(); }
 
+  Also can be specified as a nested configuration flag:
+
+  .. code-block:: c++
+
+    # Example of usage:
+    AllowShortFunctionsOnASingleLine: InlineOnly
+
+    # or more granular control:
+    AllowShortFunctionsOnASingleLine:
+      Empty: false
+      Inline: true
+      All: false
+
+  * ``bool Empty`` Merge top-level empty functions.
+
+    .. code-block:: c++
+
+      void f() {}
+      void f2() {
+        bar2();
+      }
+      void f3() { /* comment */ }
+
+  * ``bool Inline`` Merge functions defined inside a class.
+
+    .. code-block:: c++
+
+      class Foo {
+        void f() { foo(); }
+        void g() {}
+      };
+      void f() {
+        foo();
+      }
+      void f() {
+      }
+
+  * ``bool Other`` Merge all functions fitting on a single line. Please note that this
----------------
irymarchyk wrote:

Should we expose this option to user? I am not sure what it means if we set only Other, but not others - then C/C++ code will behave like SFS_All. Probably we should leave it to only set it when user sets 'All' in configuration.

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


More information about the cfe-commits mailing list