[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 08:54:29 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);
----------------
brandb97 wrote:
Emm, I am actually making sure merge short function should be subject to column limit. But as you requested to remove, I would remove them.
https://github.com/llvm/llvm-project/pull/151428
More information about the cfe-commits
mailing list