[clang] [clang-format]: Add `Custom` to `ShortFunctionStyle`; add new AllowShortFunctionsOnASingleLineOptions for granular setup (PR #134337)
Owen Pan via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 4 01:19:37 PDT 2025
================
@@ -871,13 +871,81 @@ struct FormatStyle {
/// void f() { bar(); }
/// \endcode
SFS_All,
+ /// Configure merge behavior using AllowShortFunctionsOnASingleLineOptions
+ SFS_Custom,
};
/// Dependent on the value, ``int f() { return 0; }`` can be put on a
/// single line.
/// \version 3.5
ShortFunctionStyle AllowShortFunctionsOnASingleLine;
+ /// Precise control over merging short functions
+ /// \code
+ /// # Should be declared this way:
+ /// AllowShortFunctionsOnASingleLine: Custom
+ /// AllowShortFunctionsOnASingleLineOptions:
+ /// Empty: false
+ /// Inline: true
+ /// All: false
+ /// \endcode
+ struct ShortFunctionMergeFlags {
+ /// Only merge empty functions.
+ /// \code
+ /// void f() {}
+ /// void f2() {
+ /// bar2();
+ /// }
+ /// \endcode
+ bool Empty;
+ /// Only merge functions defined inside a class.
+ /// \code
+ /// class Foo {
+ /// void f() { foo(); }
+ /// };
+ /// void f() {
+ /// foo();
+ /// }
+ /// void f() {}
+ /// \endcode
+ bool Inline;
+ /// Merge all functions fitting on a single line.
+ /// \code
+ /// class Foo {
+ /// void f() { foo(); }
+ /// };
+ /// void f() { bar(); }
+ /// \endcode
+ bool All;
----------------
owenca wrote:
```suggestion
bool Other;
```
Below is the equivalence table based on my understanding:
| `enum` | `Custom` |
| --- | --- |
| `SFS_None` | everything set to `false` |
| `SFS_InlineOnly` | only `Inline` set to `true` |
| `SFS_Empty` | only `Empty` set to `true` |
| `SFS_Inline` | both `Inline` and `Empty` set to `true` |
| `SFS_All` | everything set to `true` |
https://github.com/llvm/llvm-project/pull/134337
More information about the cfe-commits
mailing list