Skip to content

Commit 58a5c46

Browse files
authored
[clang-format] Fix a bug in BWACS_MultiLine (#136281)
Fixes #136266
1 parent ab4c939 commit 58a5c46

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

clang/lib/Format/UnwrappedLineFormatter.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,8 @@ class LineJoiner {
907907
// { <-- current Line
908908
// baz();
909909
// }
910-
if (Line.First == Line.Last && Line.First->isNot(TT_FunctionLBrace) &&
910+
if (Line.First == Line.Last &&
911+
Line.First->is(TT_ControlStatementLBrace) &&
911912
Style.BraceWrapping.AfterControlStatement ==
912913
FormatStyle::BWACS_MultiLine) {
913914
return 0;

clang/unittests/Format/FormatTest.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2866,27 +2866,29 @@ TEST_F(FormatTest, ShortEnums) {
28662866
}
28672867

28682868
TEST_F(FormatTest, ShortCompoundRequirement) {
2869+
constexpr StringRef Code("template <typename T>\n"
2870+
"concept c = requires(T x) {\n"
2871+
" { x + 1 } -> std::same_as<int>;\n"
2872+
"};");
2873+
28692874
FormatStyle Style = getLLVMStyle();
28702875
EXPECT_TRUE(Style.AllowShortCompoundRequirementOnASingleLine);
2871-
verifyFormat("template <typename T>\n"
2872-
"concept c = requires(T x) {\n"
2873-
" { x + 1 } -> std::same_as<int>;\n"
2874-
"};",
2875-
Style);
2876+
verifyFormat(Code, Style);
28762877
verifyFormat("template <typename T>\n"
28772878
"concept c = requires(T x) {\n"
28782879
" { x + 1 } -> std::same_as<int>;\n"
28792880
" { x + 2 } -> std::same_as<int>;\n"
28802881
"};",
28812882
Style);
2883+
28822884
Style.AllowShortCompoundRequirementOnASingleLine = false;
28832885
verifyFormat("template <typename T>\n"
28842886
"concept c = requires(T x) {\n"
28852887
" {\n"
28862888
" x + 1\n"
28872889
" } -> std::same_as<int>;\n"
28882890
"};",
2889-
Style);
2891+
Code, Style);
28902892
verifyFormat("template <typename T>\n"
28912893
"concept c = requires(T x) {\n"
28922894
" {\n"
@@ -2897,6 +2899,11 @@ TEST_F(FormatTest, ShortCompoundRequirement) {
28972899
" } -> std::same_as<int>;\n"
28982900
"};",
28992901
Style);
2902+
2903+
Style.AllowShortCompoundRequirementOnASingleLine = true;
2904+
Style.BreakBeforeBraces = FormatStyle::BS_Custom;
2905+
Style.BraceWrapping.AfterControlStatement = FormatStyle::BWACS_MultiLine;
2906+
verifyFormat(Code, Style);
29002907
}
29012908

29022909
TEST_F(FormatTest, ShortCaseLabels) {

0 commit comments

Comments
 (0)