r215197 - clang-format: Prefer not to put lambdas on a single line.
Daniel Jasper
djasper at google.com
Fri Aug 8 05:00:13 PDT 2014
Author: djasper
Date: Fri Aug 8 07:00:13 2014
New Revision: 215197
URL: http://llvm.org/viewvc/llvm-project?rev=215197&view=rev
Log:
clang-format: Prefer not to put lambdas on a single line.
Before:
string abc =
SomeFunction(aaaaaaaaaaaaa, aaaaa,
[]() { SomeOtherFunctioooooooooooooooooooooooooon(); });
After:
string abc = SomeFunction(aaaaaaaaaaaaa, aaaaa, []() {
SomeOtherFunctioooooooooooooooooooooooooon();
});
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=215197&r1=215196&r2=215197&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Fri Aug 8 07:00:13 2014
@@ -1420,6 +1420,8 @@ unsigned TokenAnnotator::splitPenalty(co
return 100;
if (Left.is(tok::equal) && InFunctionDecl)
return 110;
+ if (Right.is(tok::r_brace))
+ return 1;
if (Left.opensScope())
return Left.ParameterCount > 1 ? Style.PenaltyBreakBeforeFirstCallParameter
: 19;
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=215197&r1=215196&r2=215197&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Aug 8 07:00:13 2014
@@ -8819,6 +8819,9 @@ TEST_F(FormatTest, FormatsLambdas) {
"}");
verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
" [](const aaaaaaaaaa &a) { return a; });");
+ verifyFormat("string abc = SomeFunction(aaaaaaaaaaaaa, aaaaa, []() {\n"
+ " SomeOtherFunctioooooooooooooooooooooooooon();\n"
+ "});");
// Lambdas with return types.
verifyFormat("int c = []() -> int { return 2; }();\n");
More information about the cfe-commits
mailing list