diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -815,6 +815,10 @@ auto Length = LastToken->TotalLength; if (OpeningBrace) { assert(OpeningBrace != Tokens.front().Tok); + if (auto Prev = OpeningBrace->Previous; + Prev && Prev->TotalLength + ColumnLimit == OpeningBrace->TotalLength) { + Length -= ColumnLimit; + } Length -= OpeningBrace->TokenText.size() + 1; } 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 @@ -25815,6 +25815,14 @@ "}", Style); + verifyFormat("if (a) // comment\n" + " b = 1;", + "if (a) // comment\n" + "{\n" + " b = 1;\n" + "}", + Style); + verifyFormat("if (a) {\n" "Label:\n" "}",