https://github.com/owenca created https://github.com/llvm/llvm-project/pull/136281
Fixes #136266 >From 0544b824ac0f81c8bb274063c885a5fb4d41ecef Mon Sep 17 00:00:00 2001 From: Owen Pan <owenpi...@gmail.com> Date: Fri, 18 Apr 2025 01:24:54 -0700 Subject: [PATCH] [clang-format] Fix a bug in BWACS_MultiLine Fixes #136266 --- clang/lib/Format/UnwrappedLineFormatter.cpp | 3 ++- clang/unittests/Format/FormatTest.cpp | 19 +++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp index 6806ab18312ea..1298e3e7bab38 100644 --- a/clang/lib/Format/UnwrappedLineFormatter.cpp +++ b/clang/lib/Format/UnwrappedLineFormatter.cpp @@ -907,7 +907,8 @@ class LineJoiner { // { <-- current Line // baz(); // } - if (Line.First == Line.Last && Line.First->isNot(TT_FunctionLBrace) && + if (Line.First == Line.Last && + Line.First->is(TT_ControlStatementLBrace) && Style.BraceWrapping.AfterControlStatement == FormatStyle::BWACS_MultiLine) { return 0; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 49284c7f51e27..f97e8de02afb0 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -2866,19 +2866,21 @@ TEST_F(FormatTest, ShortEnums) { } TEST_F(FormatTest, ShortCompoundRequirement) { + constexpr StringRef Code("template <typename T>\n" + "concept c = requires(T x) {\n" + " { x + 1 } -> std::same_as<int>;\n" + "};"); + FormatStyle Style = getLLVMStyle(); EXPECT_TRUE(Style.AllowShortCompoundRequirementOnASingleLine); - verifyFormat("template <typename T>\n" - "concept c = requires(T x) {\n" - " { x + 1 } -> std::same_as<int>;\n" - "};", - Style); + verifyFormat(Code, Style); verifyFormat("template <typename T>\n" "concept c = requires(T x) {\n" " { x + 1 } -> std::same_as<int>;\n" " { x + 2 } -> std::same_as<int>;\n" "};", Style); + Style.AllowShortCompoundRequirementOnASingleLine = false; verifyFormat("template <typename T>\n" "concept c = requires(T x) {\n" @@ -2886,7 +2888,7 @@ TEST_F(FormatTest, ShortCompoundRequirement) { " x + 1\n" " } -> std::same_as<int>;\n" "};", - Style); + Code, Style); verifyFormat("template <typename T>\n" "concept c = requires(T x) {\n" " {\n" @@ -2897,6 +2899,11 @@ TEST_F(FormatTest, ShortCompoundRequirement) { " } -> std::same_as<int>;\n" "};", Style); + + Style.AllowShortCompoundRequirementOnASingleLine = true; + Style.BreakBeforeBraces = FormatStyle::BS_Custom; + Style.BraceWrapping.AfterControlStatement = FormatStyle::BWACS_MultiLine; + verifyFormat(Code, Style); } TEST_F(FormatTest, ShortCaseLabels) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits