]> granicus.if.org Git - clang/commitdiff
[Format/ObjC] Avoid breaking between unary operators and operands
authorBen Hamilton <benhamilton@google.com>
Fri, 19 Jul 2019 16:50:24 +0000 (16:50 +0000)
committerBen Hamilton <benhamilton@google.com>
Fri, 19 Jul 2019 16:50:24 +0000 (16:50 +0000)
Summary:
Test Plan:
  New tests added. Ran tests with:
  % ninja FormatTests && ./tools/clang/unittests/Format/FormatTests
  Confirmed tests failed before change and passed after change.

Reviewers: krasimir, djasper, sammccall, klimek

Reviewed By: sammccall

Subscribers: klimek, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64775

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

lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTestObjC.cpp

index 490c4f46135e22227687b81180c61bc249125dcc..d105d619afba81f2ceb0333ff2cadab5dc91037b 100644 (file)
@@ -2429,6 +2429,8 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line,
   if (Left.is(TT_JavaAnnotation))
     return 50;
 
+  if (Left.is(TT_UnaryOperator))
+    return 60;
   if (Left.isOneOf(tok::plus, tok::comma) && Left.Previous &&
       Left.Previous->isLabelString() &&
       (Left.NextOperator || Left.OperatorIndex != 0))
index b859d92a89ce1bfb485f663a235e35f70cbe324a..b1e289d89b66213d3efa0f8be3f492e63bfa114a 100644 (file)
@@ -886,6 +886,18 @@ TEST_F(FormatTestObjC, FormatObjCMethodExpr) {
                "                 bb:42\n"
                "                 cc:42];");
 
+  // Avoid breaking between unary operators and ObjC method expressions.
+  Style.ColumnLimit = 45;
+  verifyFormat("if (a012345678901234567890123 &&\n"
+               "    ![foo bar]) {\n"
+               "}");
+  verifyFormat("if (a012345678901234567890123 &&\n"
+               "    +[foo bar]) {\n"
+               "}");
+  verifyFormat("if (a012345678901234567890123 &&\n"
+               "    -[foo bar]) {\n"
+               "}");
+
   Style.ColumnLimit = 70;
   verifyFormat(
       "void f() {\n"