From d2130f51a197dafb969f12f98cde62b148c318d4 Mon Sep 17 00:00:00 2001 From: Francois Ferrand Date: Fri, 30 Jun 2017 20:00:02 +0000 Subject: clang-format: Do not binpack initialization lists Summary: This patch tries to avoid binpacking when initializing lists/arrays, to allow things like: static int types[] = { registerType1(), registerType2(), registerType3(), }; std::map x = { { 0, "foo fjakfjaklf kljj" }, { 1, "bar fjakfjaklf kljj" }, { 2, "stuff fjakfjaklf kljj" }, }; This is similar to how dictionnaries are formatted, and actually corresponds to the same conditions: when initializing a container (and not just 'calling' a constructor). Such formatting involves 2 things: * Line breaks around the content of the block. This can be forced by adding a comma or comment after the last element * Elements should not be binpacked This patch considers the block is an initializer list if it either ends with a comma, or follows an assignment, which seems to provide a sensible approximation. Reviewers: krasimir, djasper Reviewed By: djasper Subscribers: malcolm.parsons, klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D34238 llvm-svn: 306868 --- clang/lib/Format/ContinuationIndenter.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'clang/lib') diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index 92c8ad835ad..4197587a74c 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -1063,12 +1063,12 @@ void ContinuationIndenter::moveStatePastScopeOpener(LineState &State, Current.MatchingParen->Previous && Current.MatchingParen->Previous->is(tok::comma); AvoidBinPacking = - (Current.is(TT_ArrayInitializerLSquare) && EndsInComma) || - Current.is(TT_DictLiteral) || + EndsInComma || Current.is(TT_DictLiteral) || Style.Language == FormatStyle::LK_Proto || !Style.BinPackArguments || (NextNoComment && NextNoComment->isOneOf(TT_DesignatedInitializerPeriod, TT_DesignatedInitializerLSquare)); + BreakBeforeParameter = EndsInComma; if (Current.ParameterCount > 1) NestedBlockIndent = std::max(NestedBlockIndent, State.Column + 1); } else { -- cgit v1.2.3