[clang] 58a5c46 - [clang-format] Fix a bug in BWACS_MultiLine (#136281)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 18 18:13:05 PDT 2025
Author: Owen Pan
Date: 2025-04-18T18:13:02-07:00
New Revision: 58a5c469d97302bb33a54338cf827a4cbe4e416a
URL: https://github.com/llvm/llvm-project/commit/58a5c469d97302bb33a54338cf827a4cbe4e416a
DIFF: https://github.com/llvm/llvm-project/commit/58a5c469d97302bb33a54338cf827a4cbe4e416a.diff
LOG: [clang-format] Fix a bug in BWACS_MultiLine (#136281)
Fixes #136266
Added:
Modified:
clang/lib/Format/UnwrappedLineFormatter.cpp
clang/unittests/Format/FormatTest.cpp
Removed:
################################################################################
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 d5a6206847d68..f1b3b7dd8c0c3 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) {
More information about the cfe-commits
mailing list