[clang] [clang-format] Honor AllowShortFunctionsOnASingleLine.Other w/o Empty (PR #235369)
Gedare Bloom via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 5 17:06:04 PST 2026
================
@@ -15605,6 +15605,49 @@ TEST_F(FormatTest, CustomShortFunctionOptions) {
" return 42;\n"
"}",
CustomMixed);
+
+ // Test with Other = true, Empty = false
+ FormatStyle CustomOther = getLLVMStyle();
+ CustomOther.AllowShortFunctionsOnASingleLine = {/*Empty=*/false,
+ /*Inline=*/false,
+ /*Other=*/true};
+
+ // Non-empty functions should be on a single line
+ verifyFormat("int f() { return 42; }", CustomOther);
+ verifyFormat("class C {\n"
+ " int f() { return 42; }\n"
+ "};",
+ CustomOther);
+
+ // Empty functions should be multi-line
+ verifyFormat("int f() {\n"
+ "}",
+ CustomOther);
+ verifyFormat("class C {\n"
+ " int f() {\n"
+ " }\n"
+ "};",
+ CustomOther);
+
+ // Test with AfterFunction = true
+ CustomOther.BreakBeforeBraces = FormatStyle::BS_Custom;
+ CustomOther.BraceWrapping.AfterFunction = true;
+ verifyFormat("int f() { return 42; }", CustomOther);
+ verifyFormat("int f()\n"
+ "{\n"
+ "}",
+ CustomOther);
+
----------------
gedare wrote:
Add a test like https://github.com/llvm/llvm-project/pull/205934/changes/fa284d21b42f3cd0b042e8b542417e807afd9bc0#diff-3f6f57cda9809a57c5b79e22b4181b3f3aaac7216262d0ef44108f39b0443e9bR15598 for ` Style.BraceWrapping.SplitEmptyFunction = false;` behavior.
https://github.com/llvm/llvm-project/pull/235369
More information about the cfe-commits
mailing list