r366592 - [Format/ObjC] Avoid breaking between unary operators and operands
Ben Hamilton via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 19 09:50:24 PDT 2019
Author: benhamilton
Date: Fri Jul 19 09:50:24 2019
New Revision: 366592
URL: http://llvm.org/viewvc/llvm-project?rev=366592&view=rev
Log:
[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
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestObjC.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=366592&r1=366591&r2=366592&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Fri Jul 19 09:50:24 2019
@@ -2429,6 +2429,8 @@ unsigned TokenAnnotator::splitPenalty(co
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))
Modified: cfe/trunk/unittests/Format/FormatTestObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestObjC.cpp?rev=366592&r1=366591&r2=366592&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestObjC.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestObjC.cpp Fri Jul 19 09:50:24 2019
@@ -886,6 +886,18 @@ TEST_F(FormatTestObjC, FormatObjCMethodE
" 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"
More information about the cfe-commits
mailing list