diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp index 000a5105ca40..62759d7945f7 100644 --- a/clang/lib/Format/UnwrappedLineFormatter.cpp +++ b/clang/lib/Format/UnwrappedLineFormatter.cpp @@ -316,8 +316,13 @@ private: const AnnotatedLine *Line = nullptr; for (auto J = I - 1; J >= AnnotatedLines.begin(); --J) { assert(*J); - if (!(*J)->InPPDirective && !(*J)->isComment() && - (*J)->Level < TheLine->Level) { + if ((*J)->InPPDirective || (*J)->isComment() || + (*J)->Level > TheLine->Level) { + continue; + } + if ((*J)->Level < TheLine->Level || + (Style.BreakBeforeBraces == FormatStyle::BS_Whitesmiths && + (*J)->First->is(tok::l_brace))) { Line = *J; break; } diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 4dfa13512060..69c9ee1d1dcb 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -15142,6 +15142,13 @@ TEST_F(FormatTest, PullInlineOnlyFunctionDefinitionsIntoSingleLine) { "}", MergeInlineOnly); + MergeInlineOnly.BreakBeforeBraces = FormatStyle::BS_Whitesmiths; + verifyFormat("class Foo\n" + " {\n" + " void f() { foo(); }\n" + " };", + MergeInlineOnly); + // Also verify behavior when BraceWrapping.AfterFunction = true MergeInlineOnly.BreakBeforeBraces = FormatStyle::BS_Custom; MergeInlineOnly.BraceWrapping.AfterFunction = true;