From: Daniel Jasper Date: Thu, 26 Feb 2015 09:49:08 +0000 (+0000) Subject: clang-format: Allow breaking after "else if(" as a last resort. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a42de763ac54f79ce2f9abc8330e107275b2afc9;p=platform%2Fupstream%2Fllvm.git clang-format: Allow breaking after "else if(" as a last resort. This isn't generally nice, but better than violating the column limit. llvm-svn: 230620 --- diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 83e19c5..e233052 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1582,6 +1582,8 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line, if (Left.is(tok::l_paren) && InFunctionDecl && Style.AlignAfterOpenBracket) return 100; + if (Left.is(tok::l_paren) && Left.Previous && Left.Previous->is(tok::kw_if)) + return 1000; if (Left.is(tok::equal) && InFunctionDecl) return 110; if (Right.is(tok::r_brace)) @@ -2009,8 +2011,7 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line, if (Left.is(tok::l_paren) && Left.is(TT_AttributeParen)) return false; if (Left.is(tok::l_paren) && Left.Previous && - (Left.Previous->isOneOf(TT_BinaryOperator, TT_CastRParen) || - Left.Previous->is(tok::kw_if))) + (Left.Previous->isOneOf(TT_BinaryOperator, TT_CastRParen))) return false; if (Right.is(TT_ImplicitStringLiteral)) return false; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 3e14d14..5bf4d3c 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -493,6 +493,11 @@ TEST_F(FormatTest, ElseIf) { "} else if (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n" " aaaaaaaaaaaaaaaaaaaaaaaaaaaa)) {\n" "}"); + verifyFormat("if (a) {\n" + "} else if (\n" + " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {\n" + "}", + getLLVMStyleWithColumns(62)); } TEST_F(FormatTest, FormatsForLoop) {