[clang] [clang-format]: Add `StaticInlineOnly` and `StaticInline` options to `ShortFunctionStyle` (PR #133598)

Björn Schäpers via cfe-commits cfe-commits at lists.llvm.org
Sat Mar 29 14:22:14 PDT 2025


================
@@ -335,6 +336,32 @@ class LineJoiner {
         }
       }
 
+      if (Style.AllowShortFunctionsOnASingleLine ==
+              FormatStyle::SFS_StaticInlineOnly ||
+          Style.AllowShortFunctionsOnASingleLine ==
+              FormatStyle::SFS_StaticInline) {
+        // Check if the current line belongs to a static inline function
+        const auto *FirstNonCommentToken =
+            TheLine ? TheLine->getFirstNonComment() : nullptr;
+
+        // Look for 'static' and 'inline' keywords in any order
+        bool HasStatic = false;
+        bool HasInline = false;
+        const FormatToken *Tok = FirstNonCommentToken;
+
+        while (Tok && !Tok->is(TT_FunctionLBrace)) {
+          if (Tok->is(tok::kw_static))
+            HasStatic = true;
+          if (Tok->is(tok::kw_inline))
+            HasInline = true;
+          Tok = Tok->Next;
+        }
+
+        // If we found both static and inline, allow merging
+        if (HasStatic && HasInline)
----------------
HazardyKnusperkeks wrote:

Move this check into the `if`s of the loop, exit early.

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


More information about the cfe-commits mailing list