summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorBen Hamilton <benhamilton@google.com>2019-07-19 16:50:24 +0000
committerBen Hamilton <benhamilton@google.com>2019-07-19 16:50:24 +0000
commit86383e66266cca1a4e40538e2e6c8c13f978cfaa (patch)
treed23045ddac8faa6f0c80fb097b28dc3f620131ca /clang
parent870f49e6903dd00fdaa53eaf07180559fa42f73c (diff)
downloadbcm5719-llvm-86383e66266cca1a4e40538e2e6c8c13f978cfaa.tar.gz
bcm5719-llvm-86383e66266cca1a4e40538e2e6c8c13f978cfaa.zip
[Format/ObjC] Avoid breaking between unary operators and operands
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 llvm-svn: 366592
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp2
-rw-r--r--clang/unittests/Format/FormatTestObjC.cpp12
2 files changed, 14 insertions, 0 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 490c4f46135..d105d619afb 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -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))
diff --git a/clang/unittests/Format/FormatTestObjC.cpp b/clang/unittests/Format/FormatTestObjC.cpp
index b859d92a89c..b1e289d89b6 100644
--- a/clang/unittests/Format/FormatTestObjC.cpp
+++ b/clang/unittests/Format/FormatTestObjC.cpp
@@ -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"
OpenPOWER on IntegriCloud