]> granicus.if.org Git - clang/commitdiff
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236602 91177308-0d34-0410-b5e6-96231b3b80d8

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

index fa12d4dd7ab6012548233709dcd1f3d58cb92bab..be29239c062876c7eaaaaadf240fcbdd9d397950 100644 (file)
@@ -1684,6 +1684,9 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line,
   if (Left.is(TT_ConditionalExpr))
     return prec::Conditional;
   prec::Level Level = Left.getPrecedence();
+  if (Level != prec::Unknown)
+    return Level;
+  Level = Right.getPrecedence();
   if (Level != prec::Unknown)
     return Level;
 
index 9173061c9782804f8a7f82058a4df7ea1f157385..cb1f7bd539f3329425efe277764a3a3d23bad44b 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"