[clang] [clang-format] Add AllowShortType option for AlwaysBreakAfterReturnType. (PR #78011)

Owen Pan via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 26 18:31:19 PST 2024


================
@@ -9872,9 +9872,30 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) {
   verifyFormat("class A {\n"
                "  int f() { return 1; }\n"
                "  int g();\n"
+               "  long fooooooooooooooooooooooooooooooooooooooooooooooo::\n"
+               "      baaaaaaaaaaaaaaaaaaaar();\n"
                "};\n"
                "int f() { return 1; }\n"
-               "int g();",
+               "int g();\n"
+               "int foooooooooooooooooooooooooooooooooooooooooooooooo::\n"
+               "    baaaaaaaaaaaaaaaaaaaaar();",
+               Style);
+
+  // It is now allowed to break after a short return type if necessary.
+  Style.AlwaysBreakAfterReturnType = FormatStyle::RTBS_AllowShortType;
+  verifyFormat("class A {\n"
+               "  int f() { return 1; }\n"
+               "  int g();\n"
+               "  long\n"
+               "  "
+               "fooooooooooooooooooooooooooooooooooooooooooooooo::"
----------------
owenca wrote:

```suggestion
               "  fooooooooooooooooooooooooooooooooooooooooooooooo::"
```
Alternatively, you can set `ColumnLimit` to 60 and shorten the function name.

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


More information about the cfe-commits mailing list