[clang] [clang-format] Add option to omit wrapping for empty records (PR #151970)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 11 07:50:01 PDT 2025
=?utf-8?q?Tomáš?= Slanina <itzexpoexpo at gmail.com>,
=?utf-8?q?Tomáš?= Slanina <itzexpoexpo at gmail.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/151970 at github.com>
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff HEAD~1 HEAD --extensions h,cpp -- clang/include/clang/Format/Format.h clang/lib/Format/Format.cpp clang/lib/Format/TokenAnnotator.cpp clang/lib/Format/UnwrappedLineParser.cpp clang/unittests/Format/FormatTest.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index c6bb0103b..5d17bef78 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -961,7 +961,7 @@ static bool ShouldBreakBeforeBrace(const FormatStyle &Style,
bool IsEmptyBlock = NextToken.is(tok::r_brace);
bool WrapRecordAllowed =
!IsEmptyBlock ||
- Style.BraceWrapping.WrapEmptyRecord != FormatStyle::BWER_Never;
+ Style.BraceWrapping.WrapEmptyRecord != FormatStyle::BWER_Never;
switch (Kind) {
case tok::kw_namespace:
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index c8dff7f27..5ac92a459 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -15625,35 +15625,41 @@ TEST_F(FormatTest, WrapEmptyRecords) {
Style.BraceWrapping.SplitEmptyRecord = false;
verifyFormat("class foo\n{\n"
- " void bar();\n"
- "};", Style);
+ " void bar();\n"
+ "};",
+ Style);
verifyFormat("class foo\n{};", Style);
verifyFormat("struct foo\n{\n"
- " int bar;\n"
- "};", Style);
+ " int bar;\n"
+ "};",
+ Style);
verifyFormat("struct foo\n{};", Style);
verifyFormat("union foo\n{\n"
- " int bar;\n"
- "};", Style);
+ " int bar;\n"
+ "};",
+ Style);
verifyFormat("union foo\n{};", Style);
Style.BraceWrapping.WrapEmptyRecord = FormatStyle::BWER_Never;
verifyFormat("class foo\n{\n"
- " void bar();\n"
- "};", Style);
+ " void bar();\n"
+ "};",
+ Style);
verifyFormat("class foo {};", Style);
verifyFormat("struct foo\n{\n"
- " int bar;\n"
- "};", Style);
+ " int bar;\n"
+ "};",
+ Style);
verifyFormat("struct foo {};", Style);
verifyFormat("union foo\n{\n"
- " int bar;\n"
- "};", Style);
+ " int bar;\n"
+ "};",
+ Style);
verifyFormat("union foo {};", Style);
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/151970
More information about the cfe-commits
mailing list