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 @@ -888,7 +888,10 @@ } bool containsMustBreak(const AnnotatedLine *Line) { - for (const FormatToken *Tok = Line->First; Tok; Tok = Tok->Next) + assert(Line->First); + // Ignore the first token, because in this situation, it applies more to the + // last token of the previous line. + for (const FormatToken *Tok = Line->First->Next; Tok; Tok = Tok->Next) if (Tok->MustBreakBefore) return true; return false; 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 @@ -13832,6 +13832,20 @@ "}", format("A()\n:b(0)\n{\n}", NoColumnLimit)); + FormatStyle NoColumnLimitWrapAfterFunction = NoColumnLimit; + NoColumnLimitWrapAfterFunction.BreakBeforeBraces = FormatStyle::BS_Custom; + NoColumnLimitWrapAfterFunction.BraceWrapping.AfterFunction = true; + verifyFormat("class C {\n" + "#pragma foo\n" + " int foo { return 0; }\n" + "};", + NoColumnLimitWrapAfterFunction); + verifyFormat("class C {\n" + "#pragma foo\n" + " void foo {}\n" + "};", + NoColumnLimitWrapAfterFunction); + FormatStyle DoNotMergeNoColumnLimit = NoColumnLimit; DoNotMergeNoColumnLimit.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None; @@ -20120,9 +20134,7 @@ " int i = 5;\n" " }\n" "#ifdef _DEBUG\n" - "void bar()\n" - " {\n" - " }\n" + "void bar() {}\n" "#else\n" "void bar()\n" " {\n"