From d40ddb9df26b4a8b5cf8ad7c920a9acccb98a13c Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Tue, 10 Sep 2019 23:26:45 +0000 Subject: [PATCH] [clang-format] Apply BAS_AlwaysBreak to C++11 braced lists See PR18455. Differential Revision: https://reviews.llvm.org/D67395 llvm-svn: 371571 --- clang/lib/Format/ContinuationIndenter.cpp | 4 +++- clang/unittests/Format/FormatTest.cpp | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index 61aeb85..ede6a79 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -606,7 +606,9 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun, // disallowing any further line breaks if there is no line break after the // opening parenthesis. Don't break if it doesn't conserve columns. if (Style.AlignAfterOpenBracket == FormatStyle::BAS_AlwaysBreak && - Previous.isOneOf(tok::l_paren, TT_TemplateOpener, tok::l_square) && + (Previous.isOneOf(tok::l_paren, TT_TemplateOpener, tok::l_square) || + (Previous.is(tok::l_brace) && Previous.BlockKind != BK_Block && + Style.Cpp11BracedListStyle)) && State.Column > getNewLineColumn(State) && (!Previous.Previous || !Previous.Previous->isOneOf( tok::kw_for, tok::kw_while, tok::kw_switch)) && diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index d7859eb..7869cc5 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -7835,6 +7835,16 @@ TEST_F(FormatTest, LayoutCxx11BraceInitializers) { "};", NoBinPacking); + NoBinPacking.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak; + EXPECT_EQ("static uint8 CddDp83848Reg[] = {\n" + " CDDDP83848_BMCR_REGISTER,\n" + " CDDDP83848_BMSR_REGISTER,\n" + " CDDDP83848_RBR_REGISTER};", + format("static uint8 CddDp83848Reg[] = {CDDDP83848_BMCR_REGISTER,\n" + " CDDDP83848_BMSR_REGISTER,\n" + " CDDDP83848_RBR_REGISTER};", + NoBinPacking)); + // FIXME: The alignment of these trailing comments might be bad. Then again, // this might be utterly useless in real code. verifyFormat("Constructor::Constructor()\n" -- 2.7.4