[clang] [clang-format] Fix regression with BlockIndent of Braced Initializers (PR #108717)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Sep 14 12:18:04 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-format
Author: Gedare Bloom (gedare)
<details>
<summary>Changes</summary>
Fixes #<!-- -->73584.
---
Full diff: https://github.com/llvm/llvm-project/pull/108717.diff
2 Files Affected:
- (modified) clang/lib/Format/ContinuationIndenter.cpp (+7)
- (modified) clang/unittests/Format/FormatTest.cpp (+11)
``````````diff
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index f29f8796ea9290..5c77af2da5add5 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -348,6 +348,13 @@ bool ContinuationIndenter::canBreak(const LineState &State) {
}
}
+ // Don't allow breaking before a closing right brace of a block-indented
+ // braced list initializer if there was not already a break.
+ if (Current.is(tok::r_brace) && Current.MatchingParen &&
+ Current.isBlockIndentedInitRBrace(Style)) {
+ return CurrentState.BreakBeforeClosingBrace;
+ }
+
// If binary operators are moved to the next line (including commas for some
// styles of constructor initializers), that's always ok.
if (!Current.isOneOf(TT_BinaryOperator, tok::comma) &&
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 5ebf0d7068dd6c..d1cb2b053e33d6 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -9336,6 +9336,9 @@ TEST_F(FormatTest, AlignsAfterOpenBracket) {
" ccccccc(aaaaaaaaaaaaaaaaa, //\n"
" b));",
Style);
+ verifyFormat("aaaaaaa<bbbbbbbb> const aaaaaaaaaa{\n"
+ " aaaaaaaaaaaaa(aaaaaaaaaaa, aaaaaaaaaaaaaaaa)};",
+ Style);
Style.ColumnLimit = 30;
verifyFormat("for (int foo = 0; foo < FOO;\n"
@@ -9395,6 +9398,9 @@ TEST_F(FormatTest, AlignsAfterOpenBracket) {
"fooooooooooo(new FOO::BARRRR(\n"
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXZZZZZZZZZZZZZZZZZZZZZZZZZ()));",
Style);
+ verifyFormat("aaaaaaa<bbbbbbbb> const aaaaaaaaaa{\n"
+ " aaaaaaaaaaaaa(aaaaaaaaaaa, aaaaaaaaaaaaaaaa)};",
+ Style);
Style.AlignAfterOpenBracket = FormatStyle::BAS_BlockIndent;
Style.BinPackArguments = false;
@@ -9441,6 +9447,11 @@ TEST_F(FormatTest, AlignsAfterOpenBracket) {
" aaaaaaaaaaaaaaaa\n"
");",
Style);
+ verifyFormat("aaaaaaa<bbbbbbbb> const aaaaaaaaaa{\n"
+ " aaaaaaaaaaaaa(aaaaaaaaaaa, aaaaaaaaaaaaaaaa)\n"
+ "};",
+ Style);
+
verifyFormat("bool aaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
" const bool &aaaaaaaaa, const void *aaaaaaaaaa\n"
") const {\n"
``````````
</details>
https://github.com/llvm/llvm-project/pull/108717
More information about the cfe-commits
mailing list