r256343 - clang-format: Lower penalty for breaking between array subscripts.

Daniel Jasper via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 23 10:01:43 PST 2015


Author: djasper
Date: Wed Dec 23 12:01:43 2015
New Revision: 256343

URL: http://llvm.org/viewvc/llvm-project?rev=256343&view=rev
Log:
clang-format: Lower penalty for breaking between array subscripts.

Before:
  aaaaaaaaaaaaaaaaaaaaaaaaa[aaaaaaaaaaa(aaaaaaaaaaaa)][bbbbbbbbbbb(
      bbbbbbbbbbbb)]

After:
  aaaaaaaaaaaaaaaaaaaaaaaaa[aaaaaaaaaaa(aaaaaaaaaaaa)]
                           [bbbbbbbbbbb(bbbbbbbbbbbb)]

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=256343&r1=256342&r2=256343&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed Dec 23 12:01:43 2015
@@ -1722,7 +1722,7 @@ unsigned TokenAnnotator::splitPenalty(co
                               Right.Next->is(TT_DictLiteral)))
     return 1;
   if (Right.is(tok::l_square)) {
-    if (Style.Language == FormatStyle::LK_Proto)
+    if (Style.Language == FormatStyle::LK_Proto || Left.is(tok::r_square))
       return 1;
     // Slightly prefer formatting local lambda definitions like functions.
     if (Right.is(TT_LambdaLSquare) && Left.is(tok::equal))

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=256343&r1=256342&r2=256343&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Dec 23 12:01:43 2015
@@ -6044,6 +6044,8 @@ TEST_F(FormatTest, BreaksLongDeclaration
 TEST_F(FormatTest, FormatsArrays) {
   verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaa[aaaaaaaaaaaaaaaaaaaaaaaaa]\n"
                "                         [bbbbbbbbbbbbbbbbbbbbbbbbb] = c;");
+  verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaa[aaaaaaaaaaa(aaaaaaaaaaaa)]\n"
+               "                         [bbbbbbbbbbb(bbbbbbbbbbbb)] = c;");
   verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
                "    [bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb] = ccccccccccc;");
   verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"




More information about the cfe-commits mailing list