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 @@ -404,8 +404,9 @@ // If possible, merge the next line's wrapped left brace with the // current line. Otherwise, leave it on the next line, as this is a // multi-line control statement. - return (Style.ColumnLimit == 0 || - TheLine->Last->TotalLength <= Style.ColumnLimit) + return (Style.ColumnLimit == 0 || TheLine->Level * Style.IndentWidth + + TheLine->Last->TotalLength <= + Style.ColumnLimit) ? 1 : 0; } 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 @@ -3096,6 +3096,14 @@ " baz);", format("do{foo();}while(bar&&baz);", Style)); // Long lines should put opening brace on new line. + verifyFormat("void f() {\n" + " if (a1 && a2 &&\n" + " a3)\n" + " {\n" + " quux();\n" + " }\n" + "}", + "void f(){if(a1&&a2&&a3){quux();}}", Style); EXPECT_EQ("if (foo && bar &&\n" " baz)\n" "{\n"