[clang] [clang-format] Fix operator overload inconsistency in `BreakAfterAttributes: Always` (PR #74943)

Björn Schäpers via cfe-commits cfe-commits at lists.llvm.org
Sun Dec 10 12:08:56 PST 2023


================
@@ -583,21 +583,31 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
       return true;
   }
 
-  // If the return type spans multiple lines, wrap before the function name.
-  if (((Current.is(TT_FunctionDeclarationName) &&
-        !State.Line->ReturnTypeWrapped &&
-        // Don't break before a C# function when no break after return type.
-        (!Style.isCSharp() ||
-         Style.AlwaysBreakAfterReturnType != FormatStyle::RTBS_None) &&
-        // Don't always break between a JavaScript `function` and the function
-        // name.
-        !Style.isJavaScript()) ||
-       (Current.is(tok::kw_operator) && Previous.isNot(tok::coloncolon))) &&
-      Previous.isNot(tok::kw_template) && CurrentState.BreakBeforeParameter &&
-      (Style.isCpp() && Current.Tok.isNot(tok::kw_operator))) {
+  const auto WrapBeforeName = [&]() {
+    // If the return type spans multiple lines, wrap before the function name.
+    if (Current.isNot(TT_FunctionDeclarationName) ||
+        State.Line->ReturnTypeWrapped) {
+      return false;
+    }
+    if (Previous.is(tok::kw_template) || Current.is(tok::kw_operator))
+      return false;
+    if (!CurrentState.BreakBeforeParameter)
+      return false;
+    return true;
----------------
HazardyKnusperkeks wrote:

```suggestion
    // Don't break before a C# function when no break after return type.
    return (!Style.isCSharp() ||
         Style.AlwaysBreakAfterReturnType != FormatStyle::RTBS_None) &&
        // Don't always break between a JavaScript `function` and the function
        // name.
        !Style.isJavaScript();
```

Don't call the lambda twice.

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


More information about the cfe-commits mailing list