diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp --- a/clang/lib/Format/UnwrappedLineFormatter.cpp +++ b/clang/lib/Format/UnwrappedLineFormatter.cpp @@ -310,6 +310,8 @@ for (; J != AnnotatedLines.begin(); --J) if ((*J)->Level < TheLine->Level) break; + if ((*J)->Level == TheLine->Level) + return false; // Check if the found line starts a record. const FormatToken *LastNonComment = (*J)->Last; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -12639,6 +12639,13 @@ "};", MergeInlineOnly); verifyFormat("int f() {}", MergeInlineOnly); + // https://llvm.org/PR54147 + verifyFormat("auto lambda = []() {\n" + " // comment\n" + " f();\n" + " g();\n" + "};", + MergeInlineOnly); // Also verify behavior when BraceWrapping.AfterFunction = true MergeInlineOnly.BreakBeforeBraces = FormatStyle::BS_Custom;