From 10fc44072e81c6085f90adf8ca59cbaa37ec0ab1 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Wed, 6 May 2015 14:23:38 +0000 Subject: [PATCH] clang-format: Consider operator precedence as penalty when breaking 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 | 3 +++ unittests/Format/FormatTest.cpp | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index fa12d4dd7a..be29239c06 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -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; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 9173061c97..cb1f7bd539 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -3500,6 +3500,10 @@ TEST_F(FormatTest, ExpressionIndentationBreakingBeforeOperators) { " + cc;", Style); + verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" + " = aaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaa;", + Style); + // Forced by comments. verifyFormat( "unsigned ContentSize =\n" -- 2.40.0