r295659 - clang-format: Prevent weird line-wraps in complex lambda introducers
Daniel Jasper via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 20 04:43:48 PST 2017
Author: djasper
Date: Mon Feb 20 06:43:48 2017
New Revision: 295659
URL: http://llvm.org/viewvc/llvm-project?rev=295659&view=rev
Log:
clang-format: Prevent weird line-wraps in complex lambda introducers
Before:
aaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
[aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa]() -> ::std::
unordered_set<aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa> {
//
});
After:
aaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
[aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa]()
-> ::std::unordered_set<
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa> {
//
});
Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=295659&r1=295658&r2=295659&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Mon Feb 20 06:43:48 2017
@@ -810,6 +810,8 @@ unsigned ContinuationIndenter::moveState
if (Current.isOneOf(TT_BinaryOperator, TT_ConditionalExpr) && Newline)
State.Stack.back().NestedBlockIndent =
State.Column + Current.ColumnWidth + 1;
+ if (Current.isOneOf(TT_LambdaLSquare, TT_LambdaArrow))
+ State.Stack.back().LastSpace = State.Column;
// Insert scopes created by fake parenthesis.
const FormatToken *Previous = Current.getPreviousNonComment();
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=295659&r1=295658&r2=295659&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Feb 20 06:43:48 2017
@@ -9262,10 +9262,11 @@ TEST_F(FormatTest, FormatsLambdas) {
" << std::count_if(v.begin(), v.end(), [](int x) {\n"
" return x == 2; // force break\n"
" });");
- verifyFormat("return aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa([=](\n"
- " int iiiiiiiiiiii) {\n"
- " return aaaaaaaaaaaaaaaaaaaaaaa != aaaaaaaaaaaaaaaaaaaaaaa;\n"
- "});",
+ verifyFormat("return aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
+ " [=](int iiiiiiiiiiii) {\n"
+ " return aaaaaaaaaaaaaaaaaaaaaaa !=\n"
+ " aaaaaaaaaaaaaaaaaaaaaaa;\n"
+ " });",
getLLVMStyleWithColumns(60));
verifyFormat("SomeFunction({[&] {\n"
" // comment\n"
@@ -9351,6 +9352,15 @@ TEST_F(FormatTest, FormatsLambdas) {
"#endif\n"
" ;\n"
"};");
+
+ // Lambdas with complex multiline introducers.
+ verifyFormat(
+ "aaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
+ " [aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa]()\n"
+ " -> ::std::unordered_set<\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa> {\n"
+ " //\n"
+ " });");
}
TEST_F(FormatTest, FormatsBlocks) {
More information about the cfe-commits
mailing list