[clang] f4d52ca - [clang-format] Fix a bug in "AfterControlStatement: MultiLine"
via cfe-commits
cfe-commits at lists.llvm.org
Sat May 21 15:12:46 PDT 2022
Author: owenca
Date: 2022-05-21T15:10:21-07:00
New Revision: f4d52cad671380d9fa6c1637e1c82b7296fd7da0
URL: https://github.com/llvm/llvm-project/commit/f4d52cad671380d9fa6c1637e1c82b7296fd7da0
DIFF: https://github.com/llvm/llvm-project/commit/f4d52cad671380d9fa6c1637e1c82b7296fd7da0.diff
LOG: [clang-format] Fix a bug in "AfterControlStatement: MultiLine"
Fixes #55582.
Differential Revision: https://reviews.llvm.org/D125959
Added:
Modified:
clang/lib/Format/UnwrappedLineFormatter.cpp
clang/unittests/Format/FormatTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp
index 30755ef1086b..f92c36b449ae 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -404,8 +404,9 @@ class LineJoiner {
// 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
index 646a6ed17507..aebb44ee9acd 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -3096,6 +3096,14 @@ TEST_F(FormatTest, MultiLineControlStatements) {
" 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"
More information about the cfe-commits
mailing list