llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang-format Author: Owen Pan (owenca) <details> <summary>Changes</summary> Fixes #<!-- -->136266 --- Full diff: https://github.com/llvm/llvm-project/pull/136281.diff 2 Files Affected: - (modified) clang/lib/Format/UnwrappedLineFormatter.cpp (+2-1) - (modified) clang/unittests/Format/FormatTest.cpp (+13-6) ``````````diff 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) { `````````` </details> https://github.com/llvm/llvm-project/pull/136281 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits