r195952 - clang-format: Fix bad indentation of nested blocks.
Daniel Jasper
djasper at google.com
Fri Nov 29 00:46:22 PST 2013
Author: djasper
Date: Fri Nov 29 02:46:20 2013
New Revision: 195952
URL: http://llvm.org/viewvc/llvm-project?rev=195952&view=rev
Log:
clang-format: Fix bad indentation of nested blocks.
Before:
DEBUG( //
{ f(); });
After:
DEBUG( //
{ f(); });
Also add additional test to selected formatting of individual statements
in nested blocks.
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=195952&r1=195951&r2=195952&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Fri Nov 29 02:46:20 2013
@@ -340,7 +340,8 @@ unsigned ContinuationIndenter::addTokenO
Penalty += Style.PenaltyBreakFirstLessLess;
if (Current.is(tok::l_brace) && Current.BlockKind == BK_Block) {
- State.Column = State.FirstIndent;
+ State.Column =
+ State.ParenLevel == 0 ? State.FirstIndent : State.Stack.back().Indent;
} else if (Current.isOneOf(tok::r_brace, tok::r_square)) {
if (Current.closesBlockTypeList(Style) ||
(Current.MatchingParen &&
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=195952&r1=195951&r2=195952&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Nov 29 02:46:20 2013
@@ -2465,6 +2465,14 @@ TEST_F(FormatTest, LayoutNestedBlocks) {
" somethingelse();\n"
"});",
getLLVMStyleWithColumns(40));
+ verifyFormat("DEBUG( //\n"
+ " { f(); }, a);");
+ verifyFormat("DEBUG( //\n"
+ " {\n"
+ " f(); //\n"
+ " },\n"
+ " a);");
+
EXPECT_EQ("call(parameter, {\n"
" something();\n"
" // Comment too\n"
@@ -2532,6 +2540,15 @@ TEST_F(FormatTest, IndividualStatementsO
" int j;\n"
"} ) ;",
41, 1, getLLVMStyle()));
+ EXPECT_EQ("DEBUG( {\n"
+ " int i;\n"
+ " int j;\n"
+ "} ) ;",
+ format("DEBUG( {\n"
+ " int i;\n"
+ " int j;\n"
+ "} ) ;",
+ 41, 1, getLLVMStyle()));
EXPECT_EQ("DEBUG({\n"
" int i;\n"
" int j;\n"
More information about the cfe-commits
mailing list