[clang] [clang-format] allow short function body on a single line (PR #151428)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 28 19:49:32 PDT 2025
================
@@ -14996,6 +14996,29 @@ TEST_F(FormatTest, SplitEmptyFunctionButNotRecord) {
Style);
}
+TEST_F(FormatTest, SplitShortFunction) {
+ FormatStyle Style = getLLVMStyleWithColumns(40);
+ Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None;
+ Style.AllowShortBlocksOnASingleLine = FormatStyle::SBS_Always;
+ Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+ Style.BraceWrapping.AfterFunction = true;
+
+ verifyFormat("int foo()\n"
+ "{ return 1; }",
+ Style);
+ verifyFormat("int foo()\n"
+ "{\n"
+ " // comment\n"
+ " return 1;\n"
+ "}",
+ Style);
+ verifyFormat("int foo()\n"
+ "{\n"
+ " return 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1;\n"
+ "}",
+ Style);
----------------
owenca wrote:
These test cases can pass with or without your patch, so they are probably redundant as they should already be covered in the merging simple block tests. If not, they should be added there in a separate patch.
https://github.com/llvm/llvm-project/pull/151428
More information about the cfe-commits
mailing list