clang-format: Consider operator precedence as penalty when breaking
authorDaniel Jasper <djasper@google.com>
Wed, 6 May 2015 14:23:38 +0000 (14:23 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 6 May 2015 14:23:38 +0000 (14:23 +0000)
before operators.

This fixes llvm.org/23382.

llvm-svn: 236602

clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp

index fa12d4d..be29239 100644 (file)
@@ -1686,6 +1686,9 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line,
   prec::Level Level = Left.getPrecedence();
   if (Level != prec::Unknown)
     return Level;
+  Level = Right.getPrecedence();
+  if (Level != prec::Unknown)
+    return Level;
 
   return 3;
 }
index 9173061..cb1f7bd 100644 (file)
@@ -3500,6 +3500,10 @@ TEST_F(FormatTest, ExpressionIndentationBreakingBeforeOperators) {
       "             + cc;",
       Style);
 
+  verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
+               "    = aaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaa;",
+               Style);
+
   // Forced by comments.
   verifyFormat(
       "unsigned ContentSize =\n"