[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 06:59:59 PDT 2025


================
@@ -5687,11 +5687,11 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
     if (Right.is(tok::r_brace) && Left.is(tok::l_brace) &&
         !Left.Children.empty()) {
       // Support AllowShortFunctionsOnASingleLine for JavaScript.
-      return Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_None ||
-             Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_Empty ||
+      return (!Style.AllowShortFunctionsOnASingleLine.Inline &&
+              !Style.AllowShortFunctionsOnASingleLine.Other) ||
              (Left.NestingLevel == 0 && Line.Level == 0 &&
-              Style.AllowShortFunctionsOnASingleLine &
-                  FormatStyle::SFS_InlineOnly);
+              Style.AllowShortFunctionsOnASingleLine.Inline &&
+              !Style.AllowShortFunctionsOnASingleLine.Other);
----------------
sstwcw wrote:

It looks like you should not add inline here.  The old check uses `&`.  That is same as comparing against `SFS_All`.  The idea is that the brace should be on a new line if either the `AllosShortFunctionsOnASingleLine` is completely disabled, or the function is at the top level and the other option is disabled.

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


More information about the cfe-commits mailing list