Index: clang/lib/Format/Format.cpp =================================================================== --- clang/lib/Format/Format.cpp +++ clang/lib/Format/Format.cpp @@ -1855,7 +1855,7 @@ assert(Token->BraceCount == -1); Brace = '{'; } else { - Brace = std::string(Token->BraceCount, '}'); + Brace = '\n' + std::string(Token->BraceCount, '}'); } Token->BraceCount = 0; const auto Start = Token->Tok.getEndLoc(); Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -2338,8 +2338,10 @@ for (const auto &L : llvm::reverse(*CurrentLines)) { if (!L.InPPDirective) { Tok = getLastNonComment(L); - if (Tok) + if (Tok) { + Tok = L.Tokens.back().Tok; break; + } } } assert(Tok); Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -24481,6 +24481,13 @@ " f();", Style); + verifyFormat("if (a) {\n" + " f(); // comment\n" + "}", + "if (a)" + " f(); // comment", + Style); + verifyFormat("if (a) {\n" " f();\n" "}\n"