summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/ContinuationIndenter.cpp
diff options
context:
space:
mode:
authorFrancois Ferrand <thetypz@gmail.com>2018-05-16 08:25:03 +0000
committerFrancois Ferrand <thetypz@gmail.com>2018-05-16 08:25:03 +0000
commit58e6fe5b54b74d3f7aab29c151ed24ecb259c553 (patch)
tree93beabf82cfeb58c48ef113d2d7387e969646828 /clang/lib/Format/ContinuationIndenter.cpp
parent5df1ef7a8c04cd2b04d01c243c67d394ed7e7093 (diff)
downloadbcm5719-llvm-58e6fe5b54b74d3f7aab29c151ed24ecb259c553.tar.gz
bcm5719-llvm-58e6fe5b54b74d3f7aab29c151ed24ecb259c553.zip
clang-format: Allow optimizer to break template declaration.
Summary: Introduce `PenaltyBreakTemplateDeclaration` to control the penalty, and change `AlwaysBreakTemplateDeclarations` to an enum with 3 modes: * `No` for regular, penalty based, wrapping of template declaration * `MultiLine` for always wrapping before multi-line declarations (e.g. same as legacy behavior when `AlwaysBreakTemplateDeclarations=false`) * `Yes` for always wrapping (e.g. same as legacy behavior when `AlwaysBreakTemplateDeclarations=true`) Reviewers: krasimir, djasper, klimek Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D42684 llvm-svn: 332436
Diffstat (limited to 'clang/lib/Format/ContinuationIndenter.cpp')
-rw-r--r--clang/lib/Format/ContinuationIndenter.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index 20eb5c03b8b..9a07c5ed591 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -402,6 +402,12 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
Style.Language == FormatStyle::LK_JavaScript))
return true;
+ // If the template declaration spans multiple lines, force wrap before the
+ // function/class declaration
+ if (Previous.ClosesTemplateDeclaration &&
+ State.Stack.back().BreakBeforeParameter)
+ return true;
+
if (State.Column <= NewLineColumn)
return false;
@@ -453,7 +459,7 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
// for cases where the entire line does not fit on a single line as a
// different LineFormatter would be used otherwise.
if (Previous.ClosesTemplateDeclaration)
- return true;
+ return Style.AlwaysBreakTemplateDeclarations != FormatStyle::BTDS_No;
if (Previous.is(TT_FunctionAnnotationRParen))
return true;
if (Previous.is(TT_LeadingJavaAnnotation) && Current.isNot(tok::l_paren) &&
OpenPOWER on IntegriCloud