r194204 - clang-format: Fix corner case for brace alignment.
Daniel Jasper
djasper at google.com
Thu Nov 7 06:02:28 PST 2013
Author: djasper
Date: Thu Nov 7 08:02:28 2013
New Revision: 194204
URL: http://llvm.org/viewvc/llvm-project?rev=194204&view=rev
Log:
clang-format: Fix corner case for brace alignment.
Before:
Constructor::Constructor()
: some_value{ //
aaaaaaa //
} {}
After:
Constructor::Constructor()
: some_value{ //
aaaaaaa //
} {}
Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=194204&r1=194203&r2=194204&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Thu Nov 7 08:02:28 2013
@@ -337,7 +337,9 @@ unsigned ContinuationIndenter::addTokenO
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;
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=194204&r1=194203&r2=194204&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Nov 7 08:02:28 2013
@@ -4543,6 +4543,11 @@ TEST_F(FormatTest, LayoutCxx11Constructo
" T member = {arg1, arg2};\n"
"};",
NoSpaces);
+ verifyFormat("Constructor::Constructor()\n"
+ " : some_value{ //\n"
+ " aaaaaaa //\n"
+ " } {}",
+ NoSpaces);
}
TEST_F(FormatTest, FormatsBracedListsInColumnLayout) {
More information about the cfe-commits
mailing list