From: Daniel Jasper Date: Thu, 27 Aug 2015 11:59:31 +0000 (+0000) Subject: clang-format: Don't let a leading "template <..>" lead to wrapped initializers. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=41899787fa8a5a576511e42c62d0e29cacaac35b;p=clang clang-format: Don't let a leading "template <..>" lead to wrapped initializers. Before: Constructor() : initializer(0) {} template Constructor() : initializer(0) {} After: Constructor() : initializer(0) {} template Constructor() : initializer(0) {} git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@246146 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp index f1d53e089a..c5b768b567 100644 --- a/lib/Format/ContinuationIndenter.cpp +++ b/lib/Format/ContinuationIndenter.cpp @@ -158,6 +158,9 @@ bool ContinuationIndenter::mustBreak(const LineState &State) { getColumnLimit(State)) return true; if (Current.is(TT_CtorInitializerColon) && + (State.Column + State.Line->Last->TotalLength - Current.TotalLength + 2 > + getColumnLimit(State) || + State.Stack.back().BreakBeforeParameter) && ((Style.AllowShortFunctionsOnASingleLine != FormatStyle::SFS_All) || Style.BreakConstructorInitializersBeforeComma || Style.ColumnLimit != 0)) return true; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 691a446d16..cda8ce4510 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -3519,6 +3519,10 @@ TEST_F(FormatTest, ConstructorInitializers) { " : Inttializer(FitsOnTheLine) {}", getLLVMStyleWithColumns(43)); + verifyFormat("template \n" + "Constructor() : Initializer(FitsOnTheLine) {}", + getLLVMStyleWithColumns(45)); + verifyFormat( "SomeClass::Constructor()\n" " : aaaaaaaaaaaaa(aaaaaaaaaaaaaa), aaaaaaaaaaaaaaa(aaaaaaaaaaaa) {}"); @@ -3531,6 +3535,9 @@ TEST_F(FormatTest, ConstructorInitializers) { "SomeClass::Constructor()\n" " : aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa),\n" " aaaaaaaaaaaaaaa(aaaaaaaaaaaa) {}"); + verifyFormat("Constructor(aaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n" + " aaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)\n" + " : aaaaaaaaaa(aaaaaa) {}"); verifyFormat("Constructor()\n" " : aaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaa),\n"