aboutsummaryrefslogtreecommitdiff
path: root/clang
diff options
context:
space:
mode:
authorGedare Bloom <gedare@rtems.org>2024-09-22 15:31:19 -0600
committerGitHub <noreply@github.com>2024-09-22 14:31:19 -0700
commitdf935ff4eca91013553edbf3ca1d45b568f6709f (patch)
tree74bb3214035ab825337e6439485e36d24cc6670d /clang
parent53266f73f037bd20bcbbd7852fd0c6a7703b4c38 (diff)
downloadllvm-df935ff4eca91013553edbf3ca1d45b568f6709f.zip
llvm-df935ff4eca91013553edbf3ca1d45b568f6709f.tar.gz
llvm-df935ff4eca91013553edbf3ca1d45b568f6709f.tar.bz2
[clang-format] Fix regression with BlockIndent of Braced Initializers (#108717)
Fixes #73584.
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Format/ContinuationIndenter.cpp7
-rw-r--r--clang/unittests/Format/FormatTest.cpp5
2 files changed, 12 insertions, 0 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index 4e9ae41..4df8dc8 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 brace of a block-indented braced list
+ // initializer if there isn't 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 53aa93a..5d386c1 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -9441,6 +9441,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"