From 16a8b0e7c53ce57fab033ad59f45c619564ff1ef Mon Sep 17 00:00:00 2001 From: Daniel Jasper <djasper@google.com> Date: Thu, 7 Nov 2013 14:02:28 +0000 Subject: [PATCH] clang-format: Fix corner case for brace alignment. Before: Constructor::Constructor() : some_value{ // aaaaaaa // } {} After: Constructor::Constructor() : some_value{ // aaaaaaa // } {} git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@194204 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/ContinuationIndenter.cpp | 4 +++- unittests/Format/FormatTest.cpp | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp index 74cfbf0e90..d2da252a60 100644 --- a/lib/Format/ContinuationIndenter.cpp +++ b/lib/Format/ContinuationIndenter.cpp @@ -337,7 +337,9 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State, if (Current.is(tok::l_brace) && Current.BlockKind == BK_Block) { State.Column = State.FirstIndent; } else if (Current.isOneOf(tok::r_brace, tok::r_square)) { - if (Current.closesBlockTypeList(Style)) + if (Current.closesBlockTypeList(Style) || + (Current.MatchingParen && + Current.MatchingParen->BlockKind == BK_BracedInit)) State.Column = State.Stack[State.Stack.size() - 2].LastSpace; else State.Column = State.FirstIndent; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index fc6ef2bb5e..00c684cc40 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -4543,6 +4543,11 @@ TEST_F(FormatTest, LayoutCxx11ConstructorBraceInitializers) { " T member = {arg1, arg2};\n" "};", NoSpaces); + verifyFormat("Constructor::Constructor()\n" + " : some_value{ //\n" + " aaaaaaa //\n" + " } {}", + NoSpaces); } TEST_F(FormatTest, FormatsBracedListsInColumnLayout) { -- 2.40.0