From 00e0f4315064734255171f013b534c6e32086d7a Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Fri, 6 Sep 2013 21:46:41 +0000 Subject: [PATCH] clang-format: Fix regression introduced by r190038. Before: Constructor() : aaaaaaaaaaaaaaaaaaaa(a), bbbbbbbbbbbbbbbbbbbbbbbb(b) { } After: Constructor() : aaaaaaaaaaaaaaaaaaaa(a), bbbbbbbbbbbbbbbbbbbbbbbb(b) { } git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190209 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/ContinuationIndenter.cpp | 7 ++++++- unittests/Format/FormatTest.cpp | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp index 12cfd48f5b..40d9d2f7d2 100644 --- a/lib/Format/ContinuationIndenter.cpp +++ b/lib/Format/ContinuationIndenter.cpp @@ -225,7 +225,12 @@ unsigned ContinuationIndenter::addTokenToState(LineState &State, bool Newline, Penalty += Style.PenaltyBreakFirstLessLess; if (Current.is(tok::r_brace)) { - State.Column = State.Stack[State.Stack.size() - 2].LastSpace; + if (Current.MatchingParen && + (Current.MatchingParen->BlockKind == BK_BracedInit || + !Current.MatchingParen->Children.empty())) + State.Column = State.Stack[State.Stack.size() - 2].LastSpace; + else + State.Column = State.FirstIndent; } else if (Current.is(tok::string_literal) && State.StartOfStringLiteral != 0) { State.Column = State.StartOfStringLiteral; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 79dbad79c6..10a6316054 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -2495,6 +2495,10 @@ TEST_F(FormatTest, ConstructorInitializers) { verifyFormat("Constructor(int Parameter = 0)\n" " : aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaa),\n" " aaaaaaaaaaaa(aaaaaaaaaaaaaaaaa) {}"); + verifyFormat("Constructor()\n" + " : aaaaaaaaaaaaaaaaaaaa(a), bbbbbbbbbbbbbbbbbbbbbbbb(b) {\n" + "}", + getLLVMStyleWithColumns(60)); // Here a line could be saved by splitting the second initializer onto two // lines, but that is not desireable. -- 2.40.0