From: Daniel Jasper Date: Tue, 7 Jul 2015 13:50:50 +0000 (+0000) Subject: clang-format: Don't wrap before the ] of a lambda introducer. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a1c3b039b8828ced0c976c7be3e53eca899d7c6a;p=clang clang-format: Don't wrap before the ] of a lambda introducer. Before: return aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa([= ](int iiiiiiiiiiii) { return aaaaaaaaaaaaaaaaaaaaaaa != aaaaaaaaaaaaaaaaaaaaaaa; }); After: return aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa([=]( int iiiiiiiiiiii) { return aaaaaaaaaaaaaaaaaaaaaaa != aaaaaaaaaaaaaaaaaaaaaaa; }); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241583 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index f4b9c4eee9..a3691570cd 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -2206,6 +2206,9 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line, if (Right.is(tok::r_paren) || Right.is(TT_TemplateCloser)) return false; + if (Right.is(tok::r_square) && Right.MatchingParen && + Right.MatchingParen->is(TT_LambdaLSquare)) + return false; // We only break before r_brace if there was a corresponding break before // the l_brace, which is tracked by BreakBeforeClosingBrace. diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 19ac54ef4e..5e9c3ebcb2 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -9811,6 +9811,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" + "});", + getLLVMStyleWithColumns(60)); // Lambdas with return types. verifyFormat("int c = []() -> int { return 2; }();\n");