r241583 - clang-format: Don't wrap before the ] of a lambda introducer.

Daniel Jasper djasper at google.com
Tue Jul 7 06:50:50 PDT 2015


Author: djasper
Date: Tue Jul  7 08:50:50 2015
New Revision: 241583

URL: http://llvm.org/viewvc/llvm-project?rev=241583&view=rev
Log:
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;
  });

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=241583&r1=241582&r2=241583&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Jul  7 08:50:50 2015
@@ -2206,6 +2206,9 @@ bool TokenAnnotator::canBreakBefore(cons
 
   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.

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=241583&r1=241582&r2=241583&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Jul  7 08:50:50 2015
@@ -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");





More information about the cfe-commits mailing list