[clang] [clang-format] Honor AllowShortFunctionsOnASingleLine.Other w/o Empty (PR #235369)
Theia Dobyns via cfe-commits
cfe-commits at lists.llvm.org
Sun Nov 8 12:37:24 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);
+
+ // Inline = true still merges empty functions in a class
----------------
theia-ajax wrote:
Removed it and added full stops to other comments.
https://github.com/llvm/llvm-project/pull/235369
More information about the cfe-commits
mailing list