diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -2425,6 +2425,8 @@ 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 --- a/clang/unittests/Format/FormatTestObjC.cpp +++ b/clang/unittests/Format/FormatTestObjC.cpp @@ -886,6 +886,18 @@ " 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"